Graphql-code-generator: GraphQL parser - string variables in queries cause Unterminated string syntax error.

Created on 28 Mar 2018  路  3Comments  路  Source: dotansimha/graphql-code-generator

Expected Behavior

I expect
gql-gen --file schema.json --template typescript --out ./index.d.ts \"**/*.graphql.ts\"
to the parse the local introspection information and all query and fragment strings tagged with gql in files matching **/*.graphql.ts Including those with string arguments. e.g:

export const articleDetailQuery = gql`
  query ArticleDetail {
    Article(id: "thisisnotarealID") {
      title
    }
  }
`;

and output a typescript file with all types from the local graphQL schema and from queries and fragments.

Current Behavior

gql-gen --file schema.json --template typescript --out ./index.d.ts \"**/*.graphql.ts\" errors when trying to pass any gql tagged string which includes quotation marks.

Error: Syntax Error: Unterminated string.

query.graphql.ts (3:18)
2:   query ArticleDetail {
3:     Article(id: "
                     ^

Which prevents the output file being produced.

Steps to Reproduce

  1. npm init a new project.
  2. npm install --save-dev graphql-code-generator graphql
  3. Copy schema.txt into a schema.json file at the root of the project.
  4. Copy "export const articleDetailQuery = gql`
    query ArticleDetail {
    Article(id: "thisisnotarealID") {
    title
    }
    }
    `;
    "
    into a query.graphql.ts file at the root of the project.
  5. Copy "gql": "gql-gen --file schema.json --template typescript --out ./index.d.ts \"**/*.graphql.ts\"" into the package.json scripts array.
  6. run npm run gql

You should receive an Unterminated string error due to the string variable.

Context (Environment)

An Angular CLI, typescript and Apollo project.

bug waiting-for-release

All 3 comments

I upgraded from 0.8.14 to 0.8.21 and I am getting the same issue.

I found the issue, will release a soon fix :)

See changes here: https://github.com/dotansimha/graphql-code-generator/pull/265

Related: https://github.com/dotansimha/graphql-code-generator/pull/216

@jonaskello @jackhkmatthews

Done in 0.9.0 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotansimha picture dotansimha  路  3Comments

fvisticot picture fvisticot  路  3Comments

leonardfactory picture leonardfactory  路  3Comments

RIP21 picture RIP21  路  3Comments

edorivai picture edorivai  路  3Comments