rover icon indicating copy to clipboard operation
rover copied to clipboard

Introspection omits deprecated input fields

Open kzlsakal opened this issue 2 years ago • 3 comments

Running rover graph introspect <gateway-endpoint> returns an output that omits deprecated fields from input objects. I believe this is related to the SDL returned by the gateway rather than a problem with rover CLI.

Steps to reproduce

  • Have a gateway
    • package.json
      {
        "name": "gateway",
        "version": "1.0.0",
        "main": "index.js",
        "private": true,
        "scripts": {
          "start": "node index.js"
        },
        "dependencies": {
          "@apollo/gateway": "^2.0.5",
          "apollo-server": "^3.10.0",
          "graphql": "^16.5.0"
        }
      }
      
    • index.js
      const { ApolloServer } = require('apollo-server');
      const { ApolloGateway, IntrospectAndCompose } = require('@apollo/gateway');
      
      const gateway = new ApolloGateway({
        supergraphSdl: new IntrospectAndCompose({
          subgraphs: [
            { name: 'products', url: 'http://localhost:4001/' }
          ]
        }),
        debug: true,
      });
      
      const server = new ApolloServer({
        gateway,
        introspection: true,
        subscriptions: false,
      });
      
      
      server.listen().then(({ url }) => {
        console.log(`🚀 Gateway ready at ${url}`);
      }).catch(err => { console.error(err) });
      
  • Have a subgraph service with the following SDL:
    "Represents a schema"
    schema {
      query: RootQueryType
    }
    
    type _Service {
      sdl: String
    }
    
    union _Entity = Product
    
    type RootQueryType @extends {
      _service: _Service!
      _entities(representations: [_Any!]!): [_Entity]!
      product(productQuery: ProductQueryInput): Product
    }
    
    scalar _Any
    
    type Product @key(fields: "upc") {
      upc: String!
      name: String @deprecated(reason: "We no longer care about the product name")
      price: Int
    }
    
    input ProductQueryInput {
      upc: String
      name: String @deprecated(reason: "We really no longer care about the product name")
      price: Int
    }
    
  • Start the subgraph service and the gateway
  • Run rover graph introspect "http://localhost:4000"

Expected Result

We should get an output from rover CLI that looks like this:

type Product {
  upc: String!
  name: String @deprecated(reason: "We no longer care about the product name")
  price: Int
}
type Query {
  product(productQuery: ProductQueryInput): Product
}
input ProductQueryInput {
  upc: String
  name: String @deprecated(reason: "We really no longer care about the product name")
  price: Int
}
"Exposes a URL that specifies the behavior of this scalar."
directive @specifiedBy(
    "The URL that specifies the behavior of this scalar."
    url: String!
  ) on SCALAR

Actual Result

We get this output from rover CLI:

type Product {
  upc: String!
  name: String @deprecated(reason: "We no longer care about the product name")
  price: Int
}
type Query {
  product(productQuery: ProductQueryInput): Product
}
input ProductQueryInput {
  upc: String
  price: Int
}
"Exposes a URL that specifies the behavior of this scalar."
directive @specifiedBy(
    "The URL that specifies the behavior of this scalar."
    url: String!
  ) on SCALAR

kzlsakal avatar Aug 01 '22 23:08 kzlsakal

Howdy @kzlsakal! Thanks for reporting this issue. It seems like this is due to rover not including deprecated fields when doing introspection. Tools like Apollo Explorer, etc correctly show the deprecated fields.

I've put up a PR to fix the rover part of things and introspecting is working correctly locally. Lemme know if you see anything I missed!

benweatherman avatar Aug 02 '22 19:08 benweatherman

Thank you very much @benweatherman! This is awesome.

I noticed the same behavior in apollo schema:download --endpoint=<url> flow. I presume we will have to migrate them to use rover once this is merged in order to benefit from this fix. Is that correct?

kzlsakal avatar Aug 02 '22 19:08 kzlsakal

I presume we will have to migrate them to use rover once this is merged in order to benefit from this fix. Is that correct?

Correct. apollo still gets security updates, but things like this aren't backported.

benweatherman avatar Aug 02 '22 20:08 benweatherman