Federated GraphQL schema validation

845 views Asked by At

I have created 3 microservices in my project and implemented GraphQL Netflix DGS federation framework. https://netflix.github.io/dgs/ As a company, We are having more than 30 schemas from different micro services from different teams. But, if schema type names are duplicating each other in different micro services, we are getting run time error in Apollo gateway. I would like to know how to validate schemas? is there any engine / library / concept to validate Federated GraphQL schema on multiple microservices etc? I was checking about schema registry but looks like it is for storing schemas and versioning etc., not exactly to validate schema. Sample Schema and Error : Schema in Service 1:

type Query{
Status:status
}
type status{
id:String
Information:Info
}
type Info{
location:String
birthDate:String
gender:String
}

Schema in Service 2:

type Query{
Books:Book
}
type Book{
name:String
Information:Info
}
type Info{
author:String
Rating:String
}

In the above two schemas, Schema Type "Info" is same in both microservices. After implementing both services through ApolloGateway it throwing Runtime error: " This data graph is missing a valid configuration. A valid schema couldn't be composed. The following composition errors were found: There can be only one type named "Info"

2

There are 2 answers

0
Tiago Ferrer On

You should try to use rover. It does introspect subgraphs and check its compatibility before merge into a supergraph. Also, let's you have zero downtime during superschema updatings.

0
fuzes On

If Info is a non-shared type, I recommend you to name it BookInfo or AnotherInfo

and If you want share the Info type. you should use directive

https://www.apollographql.com/docs/federation/enterprise-guide/federated-schema-design/