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.

Option to generate type definitions side by side with *.gql files

See original GitHub issue

It would be awesome if there was a option to just generate fragments and services side by side with the *.gql files.

This example

[Component A]
  - query.gql
[Component B]
  - query.gql

resulted in this output.

[Component A]
  - query.gql
  - query.ts
[Component B]
  - query.gql
  - query.ts

Then i could define an angular component’s specific fragments without worrying about naming collisions, like I needed to do here because some other component’s grapql query had a fragment defined with the name location, and the same goes for query and mutation names.

fragment locationSelect on Location {
  id
  name
}

query GetPositionModalData {
  locations: locationsConnection(pagesize: -1) {
    edges {
      node {
        ...locationSelect
      }
    }
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:14
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
adam1658commented, Mar 11, 2019

Here’s how I’ve solved this in my codebase: Rather than using the graphql-code-generator CLI with a wildcard for all my documents, I run it using the API, once for each document:

(async function() {
  const files = await globPromise('./src/**/*.graphql');

  await Promise.all(
    files.map(filename => {
      const parsedPath = path.parse(filename);
      return generate({
        overwrite: true,
        schema: ['../graphql-schema.graphqls'],
        documents: filename,
        generates: {
          [`${parsedPath.dir}/${parsedPath.name}.generated.tsx`]: {
            plugins: [
              'typescript-common',
              // ...,
            ]
          },
        },
      });
    }),
  );
})();

It’s a new project so I have very few documents at the moment, and I haven’t seen how well it scales yet.

3reactions
dotansimhacommented, May 14, 2019

@furier @adam1658 @vreality64 @Morphexe It took some time, but it’s available (as alpha) now after this PR: https://github.com/dotansimha/graphql-code-generator/pull/1846

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generating types from a GraphQL schema
We'll use the GraphQL Code Generator library to generate types based on our GraphQL schema. There are multiple ways to provide a schema...
Read more >
Emitting the schema SDL - TypeGraphQL
To accomplish this demand, TypeGraphQL allows you to create a schema definition file in two ways. The first one is to generate it...
Read more >
Integrating GraphQL Code Generator in your frontend ...
In this article we'll try to explain and demonstrate common patterns for frontend development with GraphQL and GraphQL Code Generator.
Read more >
TypeScript with GraphQL done right - Charly Poly
Contrary to the manually maintained data types, using the GraphQL Code Generator puts the data-types maintenance on the GraphQL API side.
Read more >
Using Apollo Client to Manage GraphQL Data in our Next.js ...
When we run either of the above commands, our GraphQL queries and mutations wrapped in gql tags are converted to Typescript and output...
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