Extracting GraphQL definitions from code files
@graphql-tools/graphql-tag-pluck
will take JavaScript code as an input and will pluck all template literals provided to graphql-tag
.
Input:
Output:
Originally created because of https://graphql-code-generator.com/.
#
Usage@graphql-tools/graphql-tag-pluck
is installable via NPM (or Yarn):
Once installed you can pluck GraphQL template literals using one of the following methods:
Template literals leaded by magic comments will also be extracted :-)
supported file extensions are: .js
, .jsx
, .ts
, .tsx
, .flow
, .flow.js
, .flow.jsx
, .graphqls
, .graphql
, .gqls
, .gql
.
#
OptionsIt is recommended to look at the source code for a clearer understanding of the transformation options.
gqlMagicComment
The magic comment anchor to look for when parsing GraphQL strings. Defaults to
graphql
, which may be translated into/* GraphQL */
in code.globalGqlIdentifierName
Allows to use a global identifier instead of a module import.
modules
An array of packages that are responsible for exporting the GraphQL string parser function. The following modules are supported by default: