Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape characters within a string cause an error in client preset #9863

Open
yankydoo opened this issue Feb 22, 2024 · 0 comments
Open

Escape characters within a string cause an error in client preset #9863

yankydoo opened this issue Feb 22, 2024 · 0 comments

Comments

@yankydoo
Copy link

Which packages are impacted by your issue?

@graphql-codegen/client-preset

Describe the bug

Hey!

I'm using the client preset and I'm running into an error with a query like this:

query user {
    user(id: 1, query: "{\"$orderby\":{\"username\":\"asc\"}}") {
        id
        username
        email
    }
}

The output is as follows:

√ Parse Configuration
‼ Generate outputs
  > Generate to ./src/schemas/generated/
    √ Load GraphQL schemas
    √ Load GraphQL documents
    × Syntax Error: Expected Name, found $

I've provided a minimal reproduction here:

https://stackblitz.com/edit/github-odqmc9?file=package.json

The problem doesn't seem to be the dollar sign though, but escaped strings in general. When removing the dollar sign, the error message changes to:

√ Parse Configuration
‼ Generate outputs
  > Generate to ./src/schemas/generated/
    √ Load GraphQL schemas
    √ Load GraphQL documents
    × Syntax Error: Cannot parse the unexpected character "\\".

Workaround

During writing of this bug report I found the following workaround:

Changing the string from "{\"$orderby\":{\"username\":\"asc\"}}" to """{"$orderby":{"lastname":"asc", "firstname":"asc"}}""" does not cause the error.

Your Example Website or App

https://stackblitz.com/edit/github-odqmc9?file=package.json

Steps to Reproduce the Bug or Issue

run yarn generate

Expected behavior

As a user, I expect that an escaped double quotation in a string is processed correctly

Screenshots or Videos

No response

Platform

  • OS: Windows
  • NodeJS: 18.18.2
  • graphql version: ^16.2.0
  • @graphql-codegen/add: ^5.0.0
  • @graphql-codegen/cli: ^4.0.1
  • @graphql-codegen/typescript: 4.0.1
  • @graphql-codegen/typescript-operations: 4.0.1
  • @graphql-codegen/client-preset: 4.2.3

Codegen Config File

const config: CodegenConfig = {
  schema: 'schema.graphql',
  documents: 'document.graphql',
  generates: {
    'src/gql/': { preset: 'client' },
  },
};

Additional context

No response

@yankydoo yankydoo changed the title Escape characters within a string cause an error Escape characters within a string cause an error in client preset Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant