Comments (8)
Why not just update the tool to be able to ignore directives and scalar types? I'm not sure how useful this tool would be in other environments since most alternatives (Hasura, Apollo, etc) support schema stitching or federation, and I'd imagine people are arriving here because of the failure of AWS to handle this.
Also, this workaround is saddening because not checking in that file means every member of the team needs to remember to add it to their source. It creates a convention that is hard to enforce for large teams or for multiple product teams working in the same repository.
from graphql-schema-utilities.
As you mentioned you are seeing this issue because AppSync does add these directives definitions on top of your schema as part of AppSync core implementations. We decided not to add support to AppSync directives into this library because this is an open source solution and should NOT be limited to AppSync.
But here is a suggestion for a workaround (i have not tested it myself):
Define all AppSync directives into your local workspace and do not check that in. Similar to this issue is how to deal with AppSync predefined scalars: #15
from graphql-schema-utilities.
@hsehweil how do you not check in directives defined in local workspace when you do schema merge? quoting from #15 graphql-schema-utilities -s "{aws/types.graphql,schema.graphql,schema/**/*.graphql}"
from graphql-schema-utilities.
@hsehweil how do you not check in directives defined in local workspace when you do schema merge? quoting from #15
graphql-schema-utilities -s "{aws/types.graphql,schema.graphql,schema/**/*.graphql}"
I have the same question. Right now I'm unable to use this with AppSync, because it either fails validation, or if I add in the custom types, it gets merged into the final output, and AppSync just rejects it.
from graphql-schema-utilities.
An ugly hack I've had to do is write a quick python script to strip the AppSync scalars and directives I've had to include.
import sys
schema_file = sys.argv[1]
aws_types_file = sys.argv[2]
with open(aws_types_file, 'r') as f:
blacklist = list(filter(None, f.read().splitlines()))
with open(schema_file, 'r') as f:
print('\n'.join(filter(
lambda l: l not in blacklist,
filter(None, f.read().splitlines())
)))
I include all the AppSync scalars and directives in a graphql file, so the tool doesn't complain about missing types and whatnot, plus you get all the validation benefits. The only problem is, its now included in the output, which AppSync doesn't like, so I run this little script to remove it.
from graphql-schema-utilities.
There is an option -d
to include directives so the tool does not complain.
// .option('-d, --includeDirectives', 'By default will NOT merge the directives, unless you added this flag.', false)
from graphql-schema-utilities.
I have found that the following repository will work when you need appsync directives.
https://github.com/mattdamon108/gqlmerge
from graphql-schema-utilities.
Using AWS CDK I'm able to get the directives to upload to AppSync successfully by adding the -d
flag like @kadishmal mentioned.
I have a "root.graphql" file where I define all of the base types for my API and just put the auth directives and scalars that I need in it. Here's an example:
# define all base types so when other files extend them you don't get errors
directive @aws_oidc on FIELD_DEFINITION | OBJECT
directive @aws_api_key on FIELD_DEFINITION | OBJECT
scalar AWSDateTime
scalar AWSDate
scalar AWSURL
scalar AWSEmail
type Query
@aws_oidc @aws_api_key
type Mutation
@aws_oidc
from graphql-schema-utilities.
Related Issues (18)
- 1.1.0-beta.0: "undefined" keyword is showing in the merged schema when none of the input schema files has the schema definition. HOT 1
- 1.1.0-beta.0: graphql comments are being deleted in the merged schema if you are using # instead of """ HOT 2
- directives are not being added to the merged schema file. HOT 1
- Support for AWS AppSync scalar types HOT 1
- Programmatic access to mergeGQLSchemas is not exported.
- Errors when using LIST of mutations in @aws_subscribe HOT 3
- make the tsconfig more strict
- Test issue
- Empty type Query as mentioned in example not possible HOT 5
- @aws_subscribe directive is missing in merged schema HOT 1
- Allow --quiet / --silent option to the CLI
- Multiple implements throws Syntax error HOT 1
- Add an option to remove comments from the source files
- Show error message when merging fails
- AppSync supports multi interface implementation while this tool does not
- Warning about graphql version during installation
- 1.1.0-beta.0: directives defined under the "extended" types are not showing in the merged schema. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-schema-utilities.