Recommendation on including large third-party SDL #6195
Replies: 2 comments 3 replies
-
@kettanaito you can try |
Beta Was this translation helpful? Give feedback.
-
Once I thought better about how these generated types should behave, I came to a few useful conclusions:
It seems that my real question comes down to: how to use GraphQL Code Generator where multiple What I'm trying to do right now is to generate separate type definitions for each service, and separate Typed Document Nodes as well. This does work, but the issue is how to configure the library so it distinguishes between different GraphQL queries and doesn't attempt to process third-party queries when generating operations for my own service. generates:
./service.js:
# This glob will also catch GraphQL queries written for the third-party API
# which will fail this generation due to "X does not exist in type Y" errors.
documents: **/*.gql Let's try a loaderFirst, I've tried writing a custom // my-loader.js
const { readFileSync } = require('fs')
const { parse } = require('graphql')
module.exports = function loader(docString, config) {
const { config: pluginConfig } = config
const { serviceEquals, serviceNotEquals } = pluginConfig || {}
const contents = readFileSync(docString, { encoding: 'utf8' })
const predicates = [
serviceEquals ? contents.includes(`# service: ${serviceEquals}`) : true,
serviceNotEquals
? !contents.includes(`# service: ${serviceNotEquals}`)
: true,
]
if (!predicates.every(Boolean)) {
return
}
return parse(contents)
} generates:
./service.js:
# Still target all files
documents:
- **/*.gql:
loader: my-loader.js
config:
serviceNotEqual: github Now whenever the library analyzes a query that has a The loader cannot process non-GraphQL files. I'd also like to extract GraphQL queries from my Plugins, perhaps?Okay, so to still be able to write GraphQL in TypeScript modules I've tried writing a custom plugin. My assumption was that a plugin accepts already parsed (extracted) GraphQL query, which includes queries from TS modules. There comes another challenge: a plugin executes after the schema was validated. This means that when the library processes a GraphQL query that's meant for a third-party service, it will still fail. Since I cannot use loader outside of GraphQL files, there's no way to distinguish which query should be processed for a specific schema if those queries are written in TS modules. // Component.ts
const QUERY = gql`
# service: github
query {
viewer { login }
}
`
@dotansimha, am I even moving to the right direction here? I feel like the things I try are way too complicated for a simple use case I have: generate types and typed documents for queries that are meant for different services, but from the code that mixes those queries at the same time. It's worth mentioning that introducing a custom file pattern to distinguish between such queries should work (i.e. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey. First of all, thank you for an amazing project!
I've got a GraphQL API that uses a third-party GraphQL API. The latter ships with the ready-to-consume TypeScript definitions and SDL, which I include in my
graphql-codegen.yml
:The issue is that the third-party schema (node_modules/third-party-api/schema.graphql) is a 30k+ lines long file. Importing it makes the generated
graphql-schema.ts
file subsequently large, which in turn slows down my project's compilation time quite significantly.Please, what would you recommend in my case?
I don't know if importing from the node module would have performance implications rather than inlining the entire
schema.graphql
in the generated TypeScript file. Some sort of dead code elimination would be nice, but I understand it's rather difficult to implement, given types may be cross-referenced, resulting still in a large chunk of lines being included.Beta Was this translation helpful? Give feedback.
All reactions