ardatan / ardatan/graphql-tools

Override field types option for mergeSchemas

Open
#2,051 20 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
TypeScript
Stars
5.4k
Forks
830
Avg merge
10h 59m
Merged PRs (30d)
45

Description

I'm working on a tool that shows a visual diff between two GraphQL schemas (e.g the previous and current versions of the same schema). Added fields are marked in green color, deleted in red and modified in yellow. It's built on top of [graphql-voyager](https://www.npmjs.com/package/graphql-voyager) and uses [@graphql-inspector/core](https://www.npmjs.com/package/@graphql-inspector/core) under the hood.

In order to display the deleted fields in Voyager I merge both schemas using `mergeSchemas` from `@graphql-tools/merge`.

![graphql-voyager-visual-diff](https://user-images.githubusercontent.com/7892779/93761169-00231280-fc16-11ea-967f-95567e19c442.png)

The problem is that if e.g. `Post.content` in `schemaA` (the previous version of the schema) has the `String!` (non-null) type, but `Post.content` in `schemaB` (the current version of the schema) has the `String` (nullable) type, the `Post.content` in the result of `mergeSchemas` of `[schemaA, schemaB]` (in that order) will have the `String!` type (from the previous `schemaA`), not the `String` type (from the current `schemaB`). See the image below.

Could you please add an option for `mergeSchemas` that changes the behavior of merging non-null and nullable fields to use (override) the nullability from the latest schema from the array?

Contributor guide

Open the contributing guide

Research direction

Start at mergeSchemas in @graphql-tools/merge and review how the schemaA and schemaB ordering currently determines field types. The requested option should make the later schema's nullability override the earlier schema's nullability, and completion should be demonstrated for the String! versus String example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.