segpacto / gql-gateway

gql-gateway
MIT License
15 stars 4 forks source link

Introspection #22

Open acdoyle630 opened 2 years ago

acdoyle630 commented 2 years ago

Hi team, I'm trying to introspect a gql-gateway generated server from an ApolloServer but I am getting a 400 bad request when trying to spin up the ApolloServer with subgraphs. Wondering if theres a config or something that I'm missing?

Thanks!

gql-gateway server

import gateway from 'gql-gateway';

const port = 3001

const endpointsList = [
  { name: 'PetStore', url: "https://petstore.swagger.io/v2/swagger.json"}
];

const apolloServerConfig = {
  playground: { endpoint: 'gql-gateway' },
  introspection: true // Should be true by default
}

const localSchema = `
  extend type Order {
    pet: Pet
  }
`

const resolvers = {
  Order: {
    pet: {
      fragment: '... on Order {petId}',
      async resolve (order, args, context, info) {
        const schema = await context.resolveSchema('pet_service')

        return info.mergeInfo.delegateToSchema({
          schema,
          operation: 'query',
          fieldName: 'getPetById',
          args: { petId: order.petId },
          context,
          info
        })
      }
    }
  }
}

gateway({ localSchema, resolvers, endpointsList, apolloServerConfig }).then((server) => {
  server.listen(port).then(({ url }) => {
    console.log(`Server ready at ${url}`);
  })
})

ApolloServer

const { ApolloServer } = require('apollo-server');
const { ApolloGateway, IntrospectAndCompose } = require('@apollo/gateway');

const gateway = new ApolloGateway({
    supergraphSdl: new IntrospectAndCompose({
        subgraphs: [
            { name: 'PetStore', url: 'http://localhost:3001'}
        ]
    }),
})

const server = new ApolloServer({
    gateway
})

server.listen({ port: 4004 }).then((server) => {
    console.log(`🚀 Gateway ready at ${server.url}`);
}).catch(err => {console.error(err)});
segpacto commented 2 years ago

Hello @acdoyle630

You can take a look at #21 where it is explained how to enable introspection. Let me know if that solves your issue.

acdoyle630 commented 2 years ago

Thanks @segpacto

I tried enabling introspection in as part of the apolloServerConfig but I'm still getting a bad request. I updated the issue with an updated gql file. Any idea what might be missing?

segpacto commented 2 years ago

Hello @acdoyle630

After some digging we realize that is a feature attached to Apollo Federation subgraph specification, a feature for which the package was not initially developed for. At the same time we also realize this a nice to have.

For the moment what can we suggest, use the schema specification and add this to the localSchema property on the gql-gateway server .

Meanwhile, we will take a look at how to approach this in order to make it automatically included when there is the need to create a subgraph