0.1.0 • Published 2 years ago

generate-graphql-federation-schema-file v0.1.0

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
2 years ago

Badges

Hits

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

Questions

Contributing

Welcome you to join the development of generate-graphql-federation-schema-file.

Also, welcome PR or issue!

License

UNLICENSED

0.1.0

2 years ago