Limit graphql-codegen by kind

Limit graphql-codegen by kind


0

I am using graphql-codegen to generate types for an internal package to allow graph queries to interact with a very small subset of the massive schema of a larger application.

The stitched-schema has identically named objects of different kinds, which is resulting in invalid TypeScript as it generating identically named objects.

The duplicate named objects in stitched-schema.json have kinds “INPUT_OBJECT” and “OBJECT”.

Is there a way to filter to only generate for a specific kind, split the generated files by source .graphql/generated .tsx document or otherwise limit the generated types to only those in the documents defined in the plugin and thus queries/mutations/subscriptions we actually require.

The preference would be to exclude types for unrelated queries as this would cut the generated code from many thousand lines to just over hundred.

Omitting the typescript plugin gets me most of the way there, but it is missing Exact, Scalars and the response type definitions.

The best I can think of for now is to switch overwrite to false and manually add the missing types. Is there a better way to filter generated types through some kind of predicate and allow me to keep the package in sync with application changes.

This is our current (obfuscated) configuration-

overwrite: false
schema: "https://localhost:3000/graph"
documents: ["src/graphql/QueryOne.graphql", "src/graphql/QueryTwo.graphql", "src/graphql/QueryThree.graphql"]
config:
  withHooks: true
  reactApolloVersion: 3
generates:
  "./src/lib/graphql.tsx":
    plugins:
      - "typescript-operations"
      - "typescript-react-apollo"


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *