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

@requires directive not found in gateway list of directives #729

Closed
aleccool213 opened this issue Feb 10, 2022 · 3 comments · Fixed by #756
Closed

@requires directive not found in gateway list of directives #729

aleccool213 opened this issue Feb 10, 2022 · 3 comments · Fixed by #756

Comments

@aleccool213
Copy link
Contributor

Hi!

My team writes the gateway schema to disk for a number of reasons. We like seeing what our federated graph schema compiles to and its nice for communicating what the schema looks like to other teams (we dont use a schema registry).

We recently started to use the @requires directive in a service and the gateway doesn't list it in the directives available. Because of this, @requires does not get defined at the top of the schema file even though its being used in the schema. This breaks our linting and also doesn't follow the GraphQL schema spec closely.

Functionally @requires works as expected for the federated services.

Steps to reproduce

  1. Create a new node project on your computer.

  2. Copy and paste the example gateway code from the repo into a index.js file.

  3. Run the gateway and the two services (does this by default) by running node index.js.

  4. Query the gateway for directives

  5. See that no requires directive will exist

  6. Query service 2 for directives

  7. See that the @requires directive exists

Here is the query you can run to get directives.

query IntrospectionQuery {
  __schema {
    directives {
      name
      description
      locations
    }
  }
}
@mcollina
Copy link
Collaborator

Good spot! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@aleccool213
Copy link
Contributor Author

Sure thing!

It isn't quite clear to me in the codebase where the omitting of @requires occurs but I see its being used in relation to the gateway here:

if (directive === 'extends' || directive === 'requires') {

I'll start there and comment back when I see a clear path forward.

@aleccool213
Copy link
Contributor Author

The reason this happens is that the gateway-specific directives are filtered out of the final list of directives here:

const directives = schema.getDirectives()

This is because they aren't used in the final gateway schema, except the requires is used in both locations. I propose we do not filter out the requires directive when building the gateway schema.

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 a pull request may close this issue.

2 participants