Can someone please help :slightly_smiling_face: I ...
# orm-help
r
Can someone please help 🙂 I have spent about a day trying to figure out how to pass context from a graphql server to a remoteExecutable schema. I just can’t figure it out! In the prisma blog, I follow the example
Copy code
const fetch = require('node-fetch')
const { makeRemoteExecutableSchema, introspectSchema } = require('graphql-tools')
const { GraphQLServer } = require('graphql-yoga')
const { createHttpLink } = require('apollo-link-http')

const { DATABASE_SERVICE_ID } = require('./services')

async function run() {
  // 1. Create Apollo Link that's connected to the underlying GraphQL API
  const makeDatabaseServiceLink = () => createHttpLink({
    uri: `<https://api.graph.cool/simple/v1/${DATABASE_SERVICE_ID}>`,
    fetch
  })

  // 2. Retrieve schema definition of the underlying GraphQL API
  const databaseServiceSchemaDefinition = await introspectSchema(makeDatabaseServiceLink())

  // 3. Create the executable schema based on schema definition and Apollo Link
  const databaseServiceExecutableSchema = makeRemoteExecutableSchema({
    schema: databaseServiceSchemaDefinition,
    link: makeDatabaseServiceLink()
  })

  // 4. Create and start proxy server based on the executable schema
  const server = new GraphQLServer({ schema: databaseServiceExecutableSchema })
  server.start(() => console.log('Server is running on <http://localhost:4000'>))
}

run()
But it doesn’t seem like the context is passed to the external service. Any ideas? I have read the apollo docs, and I sort of get it, but I can’t figure it out
l
What does your GraphQLServer code look like. I Did use what you have but found forwarding on the Headers did not work so I changed the approach
Does your prisma service require an auth token?
I do have a comprehensive guide to create graphql microservices and using schema stitching to bring them together. https://gist.github.com/aqwert/6a041827d24ebec3275f75a910018e3f
🦜 1
n
that's awesome @lancej, would you like to share it here: https://github.com/prismagraphql/prisma/issues/2404? 🙂
l
@nilan Will post a link. It is a bit rough but hope to refine with the project I am working on
gucci 1
One think that is a bit manual was to change the .graphqlconfig.yml app and database elements to match the name of the microservice. from what I could see is that this is used for the playground but need to be different per microservice
I was half thinking of creating a boilerplate code to easily create a new microservice based on one of the existing ones (ideally tyopescript) and add that to the BFF service.
n
sounds interesting