Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Mixing .graphql files with tagged template literals #50

Open
mergebandit opened this issue Oct 26, 2017 · 1 comment
Open

Mixing .graphql files with tagged template literals #50

mergebandit opened this issue Oct 26, 2017 · 1 comment

Comments

@mergebandit
Copy link

Working on a project that uses primarily the gql tagged template literal for defining queries, but .graphql|.gql files for defining fragments.

Currently persistgraphql seems to be an either-or proposition. If you pass in the --js --extension=js arguments, the fragments aren't in the docMap, and as a result the following throws

extractFromAST

export function isOperationDefinition(defn: DefinitionNode): defn is OperationDefinitionNode {
  return (defn.kind === 'OperationDefinition');
}

Trace:

TypeError: Cannot read property 'kind' of undefined
    at isOperationDefinition (/Users/mergebandit/dev/super-top-secret-but-totes-badass-project/node_modules/persistgraphql/lib/src/extractFromAST.js:5:17)
    at Array.filter (<anonymous>)
    at Object.getOperationDefinitions (/Users/mergebandit/dev/super-top-secret-but-totes-badass-project/node_modules/persistgraphql/lib/src/extractFromAST.js:46:28)
    at ExtractGQL.createMapFromDocument (/Users/mergebandit/dev/super-top-secret-but-totes-badass-project/node_modules/persistgraphql/lib/src/ExtractGQL.js:70:49)
    at /Users/mergebandit/dev/super-top-secret-but-totes-badass-project/node_modules/persistgraphql/lib/src/ExtractGQL.js:99:26
    at Array.map (<anonymous>)
    at ExtractGQL.createOutputMapFromString (/Users/mergebandit/dev/super-top-secret-but-totes-badass-project/node_modules/persistgraphql/lib/src/ExtractGQL.js:95:46)
    at /Users/mergebandit/dev/super-top-secret-but-totes-badass-project/node_modules/persistgraphql/lib/src/ExtractGQL.js:132:31
    at <anonymous>

Seems to me that, if you choose the .js argument, it should still be able to extract .graphql files and merge them into the output document mapping.

@mergebandit
Copy link
Author

Fixed this locally. I'll submit a PR for you guys to tear apart and abuse me for :-D

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant