Escape characters within a string cause an error in client preset
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
-
graphqlversion: ^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