Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend introspection schema to include oneOf and specifiedByURL #501

Merged

Conversation

jimmystewpot
Copy link
Contributor

A small proposed change to the introspection query, adding support for two currently proposed directives in the GraphQL spec. They are:

  • oneOf
  • specifiedByURL

They are both available to read about here

@tomhoule
Copy link
Member

Hi! Thanks for the PR. Won't that cause a validation error on APIs that don't support these yet?

@jimmystewpot
Copy link
Contributor Author

@tomhoule, thanks for calling this out; I tested several before submitting the PR; however, after more extensive testing, it seems to be very hit-and-miss. I'll update this PR with something that allows for this to be turned on/off via command flags.

I'm unsure about this, and I hope you know the answer. In theory, I should be able to put these behind an @include(if: $variable). My understanding from reading the spec is that the server should ignore the field based on whether the variable is true or false. I've tested this across many public GraphQL services, and it is very implementation-specific.

Is my understanding of how @include and @skip should be handled by servers misguided?

@jimmystewpot
Copy link
Contributor Author

jimmystewpot commented Nov 29, 2024

I have pushed the experimental code that puts the IsOneOf behind an @include boolean. This works on more GraphQL services than it did without the include. However, some services don't seem to work as expected with that logic. I have provided this as a reference for my last comment, maybe my understanding is wrong, maybe the syntax is wrong. I'll come back to this early next week.

@jimmystewpot
Copy link
Contributor Author

jimmystewpot commented Dec 10, 2024

@tomhoule I've updated the code to remove the included logic; it seems it is not well supported. I've since been able to test various graphql APIs successfully.

  • all APIs work with the default configuration. This is the same as how it was before this PR
  • APIs that support @oneOf or @specifiedbyURL work with the options enabled and disabled

This updates the introspect-schema subcmd to have the following:

  • --specify-by-url
  • --is-one-of

Like So:

Get the schema from a live GraphQL API. The schema is printed to stdout

USAGE:
    graphql-client introspect-schema [OPTIONS] <SCHEMA_LOCATION>

ARGS:
    <SCHEMA_LOCATION>    The URL of a GraphQL endpoint to introspect

OPTIONS:
        --authorization <AUTHORIZATION>
            Set the contents of the Authorization header

    -h, --help
            Print help information

        --header <HEADERS>
            Specify custom headers. --header 'X-Name: Value'

        --is-one-of
            Introspection Option: is-one-of will enable the @oneOf directive in the introspection
            query. This is an proposed feature and is not compatible with many GraphQL servers.
            Default value is false

        --no-ssl
            Disable ssl verification. Default value is false

        --output <OUTPUT>
            Where to write the JSON for the introspected schema

        --specify-by-url
            Introspection Option: specify-by-url will enable the @specifiedByURL directive in the
            introspection query. This is an proposed feature and is not compatible with many GraphQL
            servers. Default value is false

@jimmystewpot
Copy link
Contributor Author

@tomhoule, I appreciate that you are busy and doing open source. Above and beyond, your day job isn't full of rewards. I hope you can find some time to review this PR. I want to start contributing more to improve Rust's graphql tooling, hopefully this can alleviate some of the load placed on you.

@tomhoule
Copy link
Member

Sorry for the delay, it's indeed stressful times right now. The contents of the PR look good to me, thank you for the contribution and the perseverance. Let's merge as soon as CI is green.

…on_schema.graphql, remove three clippy errors due to needless_lifetimes
@jimmystewpot
Copy link
Contributor Author

I've added a commit to fix the clippy errors and the formatting of the schema and excess newline at the end of one of the files. It should be green now

@tomhoule
Copy link
Member

Thanks!

@tomhoule tomhoule merged commit 303ed67 into graphql-rust:main Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants