0

I’m trying to get apollo-server-lambda or apollo-server-express to work with an executable schema for v3.36.

Here are the packages we use:

apollo-server-express@3.36 or apollo-server-lambda@3+
graphql-constraint-directive@3.0.0
@graphql-tools/schema@7.1.3

I ran multiple regression test to make it work, and it does not seem to hit GraphQL.

Here’s my Apollo server config:

const apolloServer = new ApolloServer({
  schema: initializeSchema(),
  plugins: [
    ApolloServerPluginLandingPageGraphQLPlayground(),
    {
    didEncounterErrors(errors) {
      logger.info(`didEncounterErrors:`)
      logger.info(errors)
    },
    async requestDidStart(requestContext) {
      logger.info(`Request started! ${requestContext}`);
      return {
        async parsingDidStart(requestContext) {
          logger.info(`Parsing started!  ${requestContext}`);
        },
  
        async validationDidStart(requestContext) {
          logger.info(`Validation started!  ${requestContext}`);
        }
      }
    },
  }],
  context: async ({ event, context, express }) => {
    logger.info(`Loading event... ${JSON.stringify(event)}`)
    const newContext = {
      headers: event.headers,
      functionName: context.functionName,
      event,
      context,
      expressRequest: express.req,
      user: {} ?? null,
    }
    logger.info(`context ${JSON.stringify(newContext)}`)
    return newContext
  },
  dataSources: () => {
    logger.info('!initializing datasource')
    initializeDbConnection()
    return {}
  },
  ...(['staging', 'production', 'demo'].includes(process.env.stage as string)
    ? { introspection: false, playground: false }
    : {}),
})

I was able to log the executable schema inside initializeSchema, but it does not seem to hit the GraphQL Typedef and Resolver after upgrading. It just goes straight to context. So, I'm kinda stumped how to make HTTP request hit the Typedef and Resolvers using makeExecutableSchema()

I just need some advise or a list of table that could help me which version works best with the given apollo-server-<server_version>.

Franz Noel
  • 1,820
  • 2
  • 23
  • 50
  • Are you using graphql-tools to accomplish this? What you're describing should be supported based on the docs: https://www.apollographql.com/docs/apollo-server/v2/api/graphql-tools/#makeexecutableschemaoptions – Kyle O'Brien Jun 21 '22 at 19:32
  • I realized that we used a plugin called `graphql-constraint-directive` which seems to only be compatible with GraphQL version 2... it changes the schema by adding constraints to the typedefs. There's no documentation available but only to remove that feature. – Franz Noel Jun 24 '22 at 05:11
  • When you say GraphQL v2, do you mean `apollo-server-express`? If so, that should still work with GraphQL Tools. – Kyle O'Brien Jun 24 '22 at 17:59
  • Yes. There had some conflicts upgrading from v2 `apollo-server-express` to v3. – Franz Noel Jun 24 '22 at 23:18
  • I suggest adding the apollo-server-express tag to your post, unfortunately, it appears the suggestion queue is full on this post. Could you also add the conflicts that you're seeing when making this upgrade? With `graphql-constraint-directive` being a community-managed package, the best path may be to [create an issue for the related GitHub repo](https://github.com/confuser/graphql-constraint-directive/issues). – Kyle O'Brien Jun 30 '22 at 14:25

0 Answers0