question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better support for GraphQL directives

See original GitHub issue

Continue the discussion from here: https://github.com/dotansimha/graphql-code-generator/pull/561

The idea is to have better support for directives such as @skip, @include, and other custom directives that become common such as @client.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
JuHwoncommented, Sep 14, 2018

i am also having an issue because i am using AWS AppSync, i got a directive @aws_subscribe in my schema. the cli returns: error: Directive aws_subscribe: Couldn't find type aws_subscribe in any of the schemas.

a nice way to handle custom/popular directives would be awesome.

1reaction
JuHwoncommented, Sep 26, 2018

Yes, my aws-enhancements.graphql contains my aws specific schema enhancements so the codegen knows about e.g. the @aws_subscribe directive. I basically followed this documentation and also checked out the already provided templates.

Since I am using this codegen for my typescript backend only I do not need the @connection directive or any other query types. (I am planning to also introduce this codegen in the frontend in the future. Though for now, I am only generating the model types for my TS backend.) My aws-enhancements.graphql is very minimal for now:

directive @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION

The way I came to this solution was by checking out the mongodb template directives. This way the codegen knows about the directive and it’s valid. I bet you can do the same with your @connection directive.

When providing a custom schema in your codegen project config I think you don’t even need to write your custom templates too. Though if you want to, I also found the types available in the handlebars templates: https://github.com/dotansimha/graphql-code-generator/blob/master/packages/graphql-codegen-core/src/types.ts With these typedefs and the already provided template source code it was very easy to create my custom templates the way I need it in my project.

So imo the graphql-code-generator does not require a better support for 3rd party directives since actually, it’s already easy to integrate them. Maybe the documentation about it should be improved. So users, who actually need custom schema enhancements get an easy manual to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Directives - Apollo GraphQL Docs
A directive decorates part of a GraphQL schema or operation with additional configuration. Tools like Apollo Server (and Apollo Client) can read a...
Read more >
GraphQL directives are underrated - LogRocket Blog
Some GraphQL servers have better support for directives than others. ... However, I believe directives are a better fit.
Read more >
Exploring GraphQL Directives in the Wild | StepZen blog
These directives make GraphQL support incremental delivery of data. They enable the clients to tell the GraphQL server what is the relative ...
Read more >
How to use GraphQL Directives efficiently - Level Up Coding
GraphQL Directives are powerful tools but they are underrated. Let's know more about what are GraphQL Directives? when should you use GraphQL Directives?...
Read more >
GraphQL directives you should know about - Hasura
Perhaps a more common use-case among API designers would be implementing a directive like this @rest directive. Its arguments take a REST ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found