generate-graphql-federation-schema-file v0.1.0
Badges
Install
npm i generate-graphql-federation-schema-file
Usage
await generateGraphQLFederationSchemaFile('http://localhost:8080/graphql'); // "federation-schema.gql" will created
Why need this?
Federation issue when pushing with apollo-cli
@nestjs/graphql, @nestjs/apollo 기반으로 GraphQL Federation Server를 만들고,
Apollo Studio에 rover cli를 사용해 Subgraph를 배포 시도하면 아래 사진과 같은 Supergraph 빌드 이슈가 발생합니다.
이 문제는 schema.gql에 GraphQL Federation과 관련된 지시문들이 누락되었기 때문에 발생한 것이며,
@nestjs/graphql, @nestjs/apollo의 버전과는 관련이 없습니다.
예시를 보겠습니다.
@ObjectType()
@Directive('@extends')
@Directive('@key(fields: "id")')
export class User {
@Field(() => Int)
@Directive('@external')
id: number;
}
code first 방식으로 schema를 만들어 봅니다.
type User {
id: Int!
}
autoSchema: true
를 통해 자동 생성된 Schema 파일에는 @extends, @key, @external 지시문이 누락되어있습니다.
type User @extends @key(fields: "id") {
id: Int! @external
}
generateGraphQLSchemaFile
을 통해 만들어진 Schema 파일에는 지시문들이 전부 추가되어 있습니다.
Apollo Studio 에도 문제 없이 정상적으로 반영됩니다.
How it works?
query {
_service {
sdl
}
}
위 쿼리를 날려 Schema 정보를 GraphQL Federation Server로부터 가져와 파일로 저장하는 단순한 구조입니다.
GraphQL Federation Server에서만 동작합니다. (Apollo docs)
Warning
Do not use GraphQL v16 (Appending "Extend" to entity incorrectly with graphql v16+)
GraphQL Federation Server가 아닌 경우, 이 기능은 동작하지 않습니다.
Questions
Contributing
Welcome you to join the development of generate-graphql-federation-schema-file.
Also, welcome PR or issue!
License
UNLICENSED
2 years ago