Giter VIP home page Giter VIP logo

Comments (8)

chimon2000 avatar chimon2000 commented on June 25, 2024 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.

hsehweil avatar hsehweil commented on June 25, 2024 4

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.

xinguaws avatar xinguaws commented on June 25, 2024

@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.

half2me avatar half2me commented on June 25, 2024

@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.

half2me avatar half2me commented on June 25, 2024

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.

kadishmal avatar kadishmal commented on June 25, 2024

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.

0xfourzerofour avatar 0xfourzerofour commented on June 25, 2024

I have found that the following repository will work when you need appsync directives.

https://github.com/mattdamon108/gqlmerge

from graphql-schema-utilities.

tqhoughton avatar tqhoughton commented on June 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.