MCPcopy
hub / github.com/dotansimha/graphql-code-generator

github.com/dotansimha/graphql-code-generator @v1.17.7 sqlite

repository ↗ · DeepWiki ↗ · release v1.17.7 ↗
4,009 symbols 14,650 edges 412 files 12 documented · 0%
README

CodeGen

npm version CircleCI Discord Chat code style: prettier renovate-app badge

graphql-code-generator.com

GraphQL Codegen 1.0 is here!

GraphQL Code Generator is a tool that generates code out of your GraphQL schema. Whether you are developing a frontend or backend, you can utilize GraphQL Code Generator to generate output from your GraphQL Schema and GraphQL Documents (query/mutation/subscription/fragment).

By analyzing the schema and documents and parsing it, GraphQL Code Generator can output code at a wide variety of formats, based on pre-defined templates or based on custom user-defined ones. Regardless of the language that you're using, GraphQL Code Generator got you covered.

GraphQL Code Generator lets you choose the output that you need, based on plugins, which are very flexible and customizable. You can also write your plugins to generate custom outputs that match your needs.

You can try this tool live on your browser and see some useful examples. Check out GraphQL Code Generator Live Examples.

We currently support and maintain these plugins (TypeScript, Flow, React, Angular, MongoDB, Stencil, Reason, and some more), and there is an active community that writes and maintains custom plugins.

Quick Start

Start by installing the basic deps of GraphQL Codegen;

$ yarn add graphql
$ yarn add -D @graphql-codegen/cli

GraphQL Code Generator lets you setup everything by simply running the following command:

$ yarn graphql-codegen init

Question by question, it will guide you through the whole process of setting up a schema, selecting plugins, picking a destination of a generated file, and a lot more.

If you don't want to use the wizard, install it by yourself and create a basic codegen.yml configuration file, point to your schema, and pick the plugins you wish to use.

Install CLI using yarn:

$ yarn add -D @graphql-codegen/cli

And create a config like below:

schema: http://localhost:3000/graphql
generates:
  src/types.ts:
    - typescript

Then, run the code-generator using graphql-codegen command:

$ yarn graphql-codegen

The command above may fetch (for example) the following GraphQL schema:

type Author {
  id: Int!
  firstName: String!
  lastName: String!
  posts(findTitle: String): [Post]
}

type Post {
  id: Int!
  title: String!
  author: Author!
}

type Query {
  posts: [Post]
}

schema {
  query: Query
}

And generate the following TypeScript typings:

export type Maybe<T> = T | null;

/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
  ID: string,
  String: string,
  Boolean: boolean,
  Int: number,
  Float: number,
};

export type Author = {
  __typename?: 'Author',
  id: Scalars['Int'],
  firstName: Scalars['String'],
  lastName: Scalars['String'],
  posts?: Maybe<Array<Maybe<Post>>>,
};

export type AuthorPostsArgs = {
  findTitle?: Maybe<Scalars['String']>
};

export type Post = {
  __typename?: 'Post',
  id: Scalars['Int'],
  title: Scalars['String'],
  author: Author,
};

export type Query = {
  __typename?: 'Query',
  posts?: Maybe<Array<Maybe<Post>>>,
};

Links

Besides our docs page, feel free to go through our published Medium articles to get a better grasp of what GraphQL Code Generator is all about:

Contributing

Feel free to open issues and pull requests. We're always welcome support from the community.

For a contribution guide, please refer to: http://graphql-code-generator.com/docs/custom-codegen/contributing

License

GitHub license

MIT

Extension points exported contracts — how you extend this code

CSharpField (Interface)
(no doc) [1 implementers]
packages/plugins/c-sharp/common/c-sharp-field-types.ts
ResolveDocumentImportResult (Interface)
(no doc)
packages/presets/near-operation-file/src/resolve-document-imports.ts
GenerateOptions (Interface)
(no doc)
packages/utils/plugins-helpers/src/types.ts
ExecutePluginOptions (Interface)
(no doc)
packages/graphql-codegen-core/src/execute-plugin.ts
PluginOption (Interface)
(no doc)
packages/graphql-codegen-cli/src/init/types.ts
SubscriptionSubscriberObject (Interface)
(no doc)
dev-test/test-schema/flow-types.flow.js
WatchQueryOptionsAlone (Interface)
(no doc)
dev-test/githunt/types.apolloAngular.sdk.ts
FlowPluginParsedConfig (Interface)
(no doc)
packages/plugins/flow/flow/src/visitor.ts

Core symbols most depended-on inside this repo

a
called by 19513
packages/plugins/flow/flow/tests/flow.js
b
called by 5316
packages/plugins/flow/flow/tests/flow.js
c
called by 3809
packages/plugins/flow/flow/tests/flow.js
d
called by 2484
packages/plugins/flow/flow/tests/flow.js
e
called by 2005
packages/plugins/flow/flow/tests/flow.js
f
called by 1754
packages/plugins/flow/flow/tests/flow.js
g
called by 1061
packages/plugins/flow/flow/tests/flow.js
h
called by 1012
packages/plugins/flow/flow/tests/flow.js

Shape

Function 3,078
Method 592
Class 160
Interface 124
Enum 55

Languages

TypeScript100%

Modules by API surface

packages/plugins/flow/flow/tests/flow.js2,611 symbols
packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts58 symbols
packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts44 symbols
dev-test/star-wars/types.refetchFn.tsx37 symbols
packages/plugins/other/visitor-plugin-common/src/utils.ts33 symbols
dev-test/githunt/types.apolloAngular.sdk.ts33 symbols
dev-test/githunt/types.reactApollo.hooks.tsx26 symbols
packages/utils/plugins-helpers/src/federation.ts24 symbols
packages/plugins/typescript/react-apollo/src/visitor.ts24 symbols
packages/plugins/typescript/apollo-angular/src/visitor.ts23 symbols
packages/plugins/flow/resolvers/src/visitor.ts23 symbols
packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts21 symbols

Dependencies from manifests, versioned

@apollo/react-common3.1.4 · 1×
@apollo/react-components3.1.5 · 1×
@apollo/react-hoc3.1.5 · 1×
@babel/preset-typescript7.10.4 · 1×
@docusaurus/core2.0.0-alpha.61 · 1×
@docusaurus/preset-classic2.0.0-alpha.61 · 1×
@graphql-cli/common4.0.0 · 1×
@graphql-codegen/add0.0.0-PLACEHOLDER · 1×
@graphql-codegen/c-sharp0.0.0-PLACEHOLDER · 1×
@graphql-codegen/c-sharp-operations0.0.0-PLACEHOLDER · 1×
@graphql-codegen/cli0.0.0-PLACEHOLDER · 1×

For agents

$ claude mcp add graphql-code-generator \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact