Graphql-code-generator: Feature request: codegen for gatsby-node's `await graphql(/* ... */)`

Created on 21 Jan 2020  路  6Comments  路  Source: dotansimha/graphql-code-generator

Is your feature request related to a problem? Please describe.

The TypeScript-Gatsby support here is great! However, there is a significant portion of Gatsby apps that are not covered via graphql-codegen:

This would be any await graphql(/* .... */) calls as part of gatsby'screatePages node API. This API is essential for creating pages programmatically using GraphQL.

The problem here is that graphql-code-generator (afaik) currently has no ability to generate types for this call so the result of await graphql is untyped.

Describe the solution you'd like

I think it makes sense to either:

  1. expand @graphql-codegen/typescript-operations to include support for graphql(/* query */)
  2. write a separate plugin to handle just gatsby-node's graphql(/* query */) calls
  3. write a generic plugin that will look for any type of tag or invocation in any typescript file and write types for it

I don't know if these options make sense but the goal is output operation types for gatsby-node calls.

Describe alternatives you've considered

stated alternative ideas above.

Additional context

I've tried writing a plugin myself that correctly parses the graphql(/* ... */) calls however it seems like graphql-codegen won't recognize/load any *.ts file (with error Unable to find any GraphQL type definitions for the following pointers:) unless it includes some known import like these:

any-ts-file.ts

import { graphql } from 'gatsby';
// or
import graphql from 'graphql-tag';

This constraint leads me to believe this kind of behavior can't be done with only plugins.

core enhancement waiting-for-release

Most helpful comment

https://github.com/ardatan/graphql-toolkit/commit/4e615bdad560c65d6864f56ff2deaf4282659c7b
In the next release of both toolkit and codegen, you won't need this extra configuration.

All 6 comments

Could you add pluckConfig like below and try again? This configuration would set 'graphql' as a default tag name instead of 'gql'.

pluckConfig:
     globalGqlIdentifierName: graphql

@ardatan oh my lord, it worked

@ricokahler Awesome! I think both gql and graphql should be default identifiers. Let's keep this open until we do these changes!

that was easier than I thought. thanks for the support!

https://github.com/ardatan/graphql-toolkit/commit/4e615bdad560c65d6864f56ff2deaf4282659c7b
In the next release of both toolkit and codegen, you won't need this extra configuration.

Available in v1.12.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zenVentzi picture zenVentzi  路  3Comments

iamdanthedev picture iamdanthedev  路  3Comments

leonardfactory picture leonardfactory  路  3Comments

quolpr picture quolpr  路  3Comments

bastman picture bastman  路  3Comments