3.0.1 • Published 3 years ago

gatsby-plugin-codegen v3.0.1

Weekly downloads
2,087
License
MIT
Repository
github
Last release
3 years ago

gatsby-plugin-codegen

Generate TypeScript/Flow definitions from your gatsby queries.

Export schema and apollo config file to give autocomplete feature in vscode through apollographql.vscode-apollo (https://marketplace.visualstudio.com/items?itemName=apollographql.vscode-apollo).

Install

npm install --save gatsby-plugin-codegen

How to use

// In your gatsby-config.js
plugins: [
  // other plugins
  {
    resolve: "gatsby-plugin-codegen",
    options: {}
  }
];

Available options

Please check the documentation of apollo tooling (https://www.npmjs.com/package/apollo) for further explanation. This plugin creates an apollo config file (apolloConfigFile), a file from the gatsby schema (localSchemaFile) and the directory for the generated types (output).

export interface PluginCodegenOptions {
  // Name of the generated apollo config file
  apolloConfigFile?: string;

  // apollo:codegen options configured for usage with gatsby, see defaultOptions
  addTypename?: boolean;
  excludes?: string[];
  includes?: string[];
  localSchemaFile?: string;
  output?: string;
  tsFileExtension?: string;
  watch?: boolean;
  tagName?: string;
  target?: "typescript" | "swift" | "flow" | "scala";

  // apollo:codegen additional options
  globalTypesFile?: string;
  mergeInFieldsFromFragmentSpreads?: boolean;
  namespace?: string;
  outputFlat?: boolean;
  passthroughCustomScalars?: boolean;
  useFlowExactObjects?: boolean;
  useReadOnlyTypes?: boolean;

  // Gatsby specific, not used in this plugin
  plugins?: unknown[];
}

const defaultOptions = {
  apolloConfigFile: "apollo.config.js",
  addTypename: false,
  excludes: [],
  localSchemaFile: "./schema.json",
  output: "__generated__",
  target: "typescript",
  tagName: "graphql",
  tsFileExtension: "d.ts",
  includes: [
    "./src/**/*.tsx",
    "./src/**/*.ts",
    "./plugins/**/*.js",
    "./node_modules/gatsby-source-contentful/src/fragments.js",
    "./node_modules/gatsby-source-datocms/fragments/*.js",
    "./node_modules/gatsby-source-sanity/fragments/*.js",
    "./node_modules/gatsby-transformer-sharp/src/fragments.js",
    // "./node_modules/gatsby-*/**/*.js" Performance reasons
  ],
  // True can result in missed error messages through the console
  // Set it the following way to catch the errors during the build and still have watch mode:
  // process.env.NODE_ENV === "development" ? true : false
  watch: false
};
1.3.0-next-1

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

3.0.0-next

3 years ago

1.3.0-next

3 years ago

1.2.14

4 years ago

1.3.0-alpha-18

4 years ago

1.3.0-alpha-14

4 years ago

1.3.0-alpha-15

4 years ago

1.3.0-alpha-16

4 years ago

1.3.0-alpha-12

4 years ago

1.3.0-alpha-13

4 years ago

1.3.0-alpha-11

4 years ago

1.3.0-alpha-10

4 years ago

1.3.0-alpha-5

4 years ago

1.3.0-alpha-4

4 years ago

1.3.0-alpha-7

4 years ago

1.3.0-alpha-6

4 years ago

1.3.0-alpha-8

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.3.0-alpha-1

4 years ago

1.3.0-alpha-3

4 years ago

1.3.0-alpha-2

4 years ago

1.2.9

4 years ago

1.2.12

4 years ago

1.3.0-alpha

4 years ago

1.2.13

4 years ago

1.2.10

4 years ago

1.2.11

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago