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

Support for @authenticated directive #332

Closed
librairica opened this issue Apr 9, 2024 · 2 comments
Closed

Support for @authenticated directive #332

librairica opened this issue Apr 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@librairica
Copy link

Is your feature request related to a problem? Please describe.
Code generation fails when the graphql schema includes the @authenticated directive.
error: invalid schema: Undefined directive authenticated.

Describe the solution you'd like
Generation works with this directive out of the box, or can be configured in genqlient.yaml.

Describe alternatives you've considered
Currently I remove instances of @authenticated from the schema using sed:
sed 's/@authenticated//' schema.graphql > schemaWithoutAuthenticated.graphql

Additional context
Doc on authenticated directive from Apollo: https://www.apollographql.com/docs/router/configuration/authorization/#authenticated

@librairica librairica added the enhancement New feature or request label Apr 9, 2024
@benjaminjkraft
Copy link
Collaborator

Hmm, I think the server/schema was supposed to provide the directive definition if it refers to the directive. (Spec language is here.) If it doesn't, you could probably just add the definition to your schema:

directive @authenticated on OBJECT | FIELD_DEFINITION | INTERFACE | SCALAR | ENUM

I'm curious though how you're getting a schema with undefined directives. Reading the docs, maybe this is something where apollo has their own @link spec that defines a different way to define directives? But I think that should only be if you're a subgraph where your client is the federation server. genqlient is a regular client, so it's generally designed to talk to your supergraph schema, which I think should resolve (really, hide) any federation fanciness. It's not necessarily a problem to use it to talk to a subgraph directly, but you'd have to work out how to handle details like this (e.g. patch in the federation definitions).

Or, if you have a concrete suggestion for what we should support (e.g. how to implement support for @link -- it's not even clear to me from reading the spec if there's a way to resolve them to an actual definition without prior knowledge), concrete suggestions are welcome!

@librairica
Copy link
Author

Thanks for the feedback! You are right that declaring the directive instead of importing it via @link solved the issue. I was able to compose a supergraph and generate off that 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants