Append the referenced fragment as a variable to the end of the GraphQL query.
Example:
import gql from 'graphql-tag';const bar = gql` fragment barFragment on Foo { field1 field2 }`;const foo = gql` query foo { foo { ...barFragment } } ${bar}`;
Options
importSources - An array of names for modules to import (default = ["graphql-tag", "@apollo/client"])
onlyMatchImportSuffix - Matches the end of the import instead of the entire name. Useful for relative imports, e.g. ./utils/graphql (default = false)
strip - Strips insignificant characters such as whitespace from the original GraphQL string literal to reduce the size of compiled AST (default = false)
transform - By default, graphql query strings will be replaced with their AST representations, but you can override that behavior and do whatever you like. One possible use case would be to implement persisted queries:
gqlTagIdentifiers - An array of names for gql tag identifiers (default = ["gql"])
// babel.config.jsplugins: [ [ "babel-plugin-graphql-tag", { strip: true, transform: (source, ast) => { const h = hash(source); // use your favorite hashing method graphqlAstHashes[h] = ast; // write this to a file when compilation is complete return { queryId: h }; } } ]]