dotansimha / dotansimha/graphql-code-generator
Generator does not work with federated schema
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Describe the bug**
The code generator throws an error when a federated schema is passed in.
**To Reproduce**
Steps to reproduce the behavior:
Hello, I am trying to break down my graphql schema into different files and modules. I am working with a federated schema. I have imported the different files and generated a `GraphQLSchema` object in an `index.ts` file like so:
```
import { gql } from "apollo-server";
import fs from "fs";
import path from "path";
import { resolvers } from "../server/resolvers";
import { buildFederatedSchema } from "@apollo/federation";
const { buildSchema } = require("graphql");
const mainSchema = gql(
fs.readFileSync(path.join(__dirname, "./schema.graphql"), "utf-8")
);
const expiryDate = gql(
fs.readFileSync(path.join(__dirname, "./expiryDate.graphql"), "utf-8")
);
export const schema = buildFederatedSchema({
resolvers,
typeDefs: [mainSchema, expiryDate],
});
```
To generate this schema for typescript, I use the code generator with the following codegen.yaml :
```
overwrite: true
schema:
- "./src/typeDefs/index.ts"
documents: null
generates:
./generated/graphql.ts:
plugins:
- "typescript"
- "typescript-resolvers"
config:
contextType: "../src/interfaces/IContext#IContext"
federation: true
useIndexSignature: true
```
When I run the command to generate the code, I get the following error:
```
Failed to load schema from ./src/typeDefs/index.ts:
Cannot read property 'concat' of undefined
TypeError: Cannot read property 'concat' of undefined
at extendDefinition (/Users/talaltoukan/Developer/Ziina/ziina/node_modules/@graphql-toolkit/common/index.cjs.js:362:45)
at Object.printSchemaWithDirectives (/Users/talaltoukan/Developer/Ziina/ziina/node_modules/@graphql-toolkit/common/index.cjs.js:342:64)
at /Users/talaltoukan/Developer/Ziina/ziina/node_modules/@graphql-toolkit/core/index.cjs.js:629:46
at Array.map ()
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.