question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gql-tag preset: Issue with indention

See original GitHub issue

Describe the bug

The graphql query passed to the generated gql function is not recognized due a mismatch in the indention.

To Reproduce Steps to reproduce the behavior:

  1. Define a graphql query as
    const checkLoggedIn = gql(/* GraphQL */ `
      query CheckLoggedIn {
        me {
          id
        }
      }
    `)
  1. Run the code generation using the gql-tag preset
  2. Observe that checkLoggedIn has type unknown.

The problem is the indention. The generated gql file has the following signature

export function gql(source: "query CheckLoggedIn {\n  me {\n    id\n  }\n}"): (typeof documents)["query CheckLoggedIn {\n  me {\n    id\n  }\n}"];

but the argument has additional indention. Indeed, if I remove the fallback to unknown in the generated gql method, then I get the following error:

Argument of type '"\n      query CheckLoggedIn {\n        me {\n          id\n        }\n      }\n    "' is not assignable to parameter of type '"query CheckLoggedIn {\n  me {\n    id\n  }\n}"'

Note the additional newline at the start, and the different amount of whitespace.

  1. My GraphQL schema:
# Put your schema here
  1. My GraphQL operations:
# Put your operations here
  1. My codegen.yml config file:
documents:  - 'src/**/*.ts'  - '!src/gql/**/*'generates:  ./src/gql/:    preset: gql-tag-operations-preset

Expected behavior

Environment:

  • OS:
  • @graphql-codegen/...: latest
  • NodeJS:

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
padorang684commented, Aug 14, 2021

I had the exact same issue, I was able to resolve it by setting the version of @graphql-tools/code-file-loader to 7.0.1 using resolutions in package.json. @graphql-tools/code-file-loader@7.0.3 seems to have introduced a breaking change, causing this issue

1reaction
n1ru4lcommented, Aug 10, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

gql-tag-operations-preset - GraphQL Code Generator
This preset generates typings for your inline gql function usages, without having to manually specify import statements for the documents.
Read more >
Filter Data from Your Views - Tableau Help
On Tableau Server and Tableau Cloud, presets are applied when the view first loads in the browser, but not when the browser or...
Read more >
Vue JavaScript Tutorial in Visual Studio Code
Vue JavaScript tutorial showing IntelliSense, debugging, and code navigation support in the Visual Studio Code editor.
Read more >
Custom Transformation - use cases with advanced SQL queries
Merging Jira Issue tables by linked issues and keys; 18Formatting a header of Jira Issue; 19Counting the definite value in a column ...
Read more >
Getting Started with Dashboards - Datadog Docs
These basic dashboards enable team discussion and speed up issue resolution. ... Browse the search results for dashboards marked Preset and see if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found