Description
In our project, we're working with multiple different graphs.
Sometimes these graphs are actually external services we do not control but we write queries to target them.
We've been using VS Code GraphQL: Language Feature Support extension for GraphQL LSP
I've been setting up GraphQL Config https://the-guild.dev/graphql/config to tell the VS Code extension which files should use which schema
Here's the config we are currently using
graphql.config.js
const mxSchema = "backend/packages/graphql-schema/schema.gen.graphql";
module.exports = {
projects: {
default: {
schema: mxSchema,
},
"backend-tests": {
schema: mxSchema,
documents: ["backend/api/src/**/__tests__/**/*.spec.ts"],
},
"server-rendering": {
schema: mxSchema,
documents: [
"backend/server-rendering/src/graphql/**/*!(.gen).{ts,tsx}",
"backend/server-rendering/src/modules/**/graphql/**/*!(.gen).{ts,tsx}",
],
},
"work-order-asset-snapshots": {
schema: mxSchema,
documents: ["backend/graphql/src/mutations/helpers/workOrderAssetSnapshot/**/*.{ts,tsx}"],
},
frontend: {
schema: mxSchema,
documents: [
"frontend/src/**/*.gql!(.gen).{ts,tsx}",
"frontend/src/graphql/**/*!(.gen).{ts,tsx}",
"frontend/src/modules/**/graphql/**/*!(.gen).{ts,tsx}",
"native/src/shared-all/graphql/**/*!(.gen).{ts,tsx}",
"native/src/shared-clients/graphql/**/*!(.gen).{ts,tsx}",
],
},
dashboard: {
schema: mxSchema,
documents: [
"dashboard/src/**/*.gql!(.gen).{ts,tsx}",
"dashboard/src/graphql/**/*!(.gen).{ts,tsx}",
"dashboard/src/modules/**/graphql/**/*!(.gen).{ts,tsx}",
"native/src/shared-all/graphql/**/*!(.gen).{ts,tsx}",
"native/src/shared-clients/graphql/**/*!(.gen).{ts,tsx}",
],
},
native: {
schema: mxSchema,
documents: [
"native/src/**/*.gql!(.gen).{ts,tsx}",
"native/src/graphql/**/*!(.gen).{ts,tsx}",
"native/src/modules/**/graphql/**/*!(.gen).{ts,tsx}",
"native/src/shared-all/graphql/**/*!(.gen).{ts,tsx}",
"native/src/shared-clients/graphql/**/*!(.gen).{ts,tsx}",
],
},
gpl: {
schema: "gql-gen/gpl.gen.graphql",
documents: "backend/common/src/core/gpl/*!(.gen).ts",
},
metal: {
schema: "backend/node_modules/@metal/graphql/schema.gen.graphql",
documents: "backend/common/src/core/metal/*!(.gen).ts",
},
},
};
You'll notice that we have multiple "client" applications targeting the same schema which allows to better understand which fragments belongs to which project.
Also at the end you'll notice that have a local copy of the gpl
project that is an external api we call and the metal
project has an sdk providing the schema that we're using as well.
Worth noting that we have a separate config for GraphQL Codegen, because the VS Code GraphQL LSP extension doesn't support multiple schema files even though the GraphQL Config standard supports it. So we stitch all our schemas into 1 big schema file and pipe this into the extension instead
Since we are starting to look into Federation, we are investigating better extension to empower our devs and was hoping Apollo's extension would support the GraphQL Config for a more standardized way to provide a great GraphQL experience to our developpers.