apollographql / federation

🌐  Build and scale a single data graph across multiple services with Apollo's federation gateway.
https://apollographql.com/docs/federation/
Other
665 stars 251 forks source link

Control the field ordering in graphql schema #3080

Open yuhanz opened 3 months ago

yuhanz commented 3 months ago

We found out from apollo-kotlin client that the schema from graphql federation look different when created with serviceList or supergraphSdl file:

  const gateway = new ApolloGateway({
    serviceList: services,
    // supergraphSdl: supergraphStr,

If ApolloGateway is created with serviceList, then the fields in a type are sorted in alphabetical order. If ApolloGateway is created with supergraphSdl, then the fields in a type are listed as they were ordered in their subgraph.

Since apollo-kotlin compiles DTO classes based on the schema, the reordering causes the constructor signature incompatible when I switch between the two modes, :( while still at the same schema.

Is there some parameter in ApolloGateway to control the behavior of field ordering in a schema? Any command line tool to sort the fields in a graphql schema could help, too.

duckki commented 3 months ago

serviceList has been deprecated. Is there a reason serviceList has to be used?

yuhanz commented 3 months ago

I see. We had an old Java client (apollo-kotlin) built upon a schema from serviceList. We have moved to supergraphSdl and that caused a newly built of the GraphQL client to be incompatible in the Java code. I guess there will be no support of the schema format of serviceList moving forward. (That's also why the app has moved to supergraphSdl) . Just want to note there is a difference between the two schema formats, and wonder if any one else built tools when they encountered the same issue.