Graphql-yoga: How to deploy on Firebase Cloud Functions?

Created on 24 Jan 2019  路  3Comments  路  Source: dotansimha/graphql-yoga

statustale

Most helpful comment

After you initialize GraphQLServer, you have to createHttpServer instead of starting the server, and then you can use the express instance on firebase functions.

const { GraphQLServer } = require('graphql-yoga');
const functions = require('firebase-functions');

const typeDefs = `
  type Query {
    hello(name: String): String!
  }
`;

const resolvers = {
  Query: {
    hello: (_, { name }) => `Hello ${name || 'World'}`,
  },
};

const server = new GraphQLServer({ typeDefs, resolvers });

const options = {
  cors: true,
};
server.createHttpServer(options);
const express = server.express

module.exports = {
  yoga: functions.https.onRequest(express),
};

All 3 comments

After you initialize GraphQLServer, you have to createHttpServer instead of starting the server, and then you can use the express instance on firebase functions.

const { GraphQLServer } = require('graphql-yoga');
const functions = require('firebase-functions');

const typeDefs = `
  type Query {
    hello(name: String): String!
  }
`;

const resolvers = {
  Query: {
    hello: (_, { name }) => `Hello ${name || 'World'}`,
  },
};

const server = new GraphQLServer({ typeDefs, resolvers });

const options = {
  cors: true,
};
server.createHttpServer(options);
const express = server.express

module.exports = {
  yoga: functions.https.onRequest(express),
};

Due to inactivity of this issue we have marked it stale. It will be closed if no further activity occurs.

Hey :wave:, It seems like this issue has been inactive for some time. In need for maintaining clear overview of the issues concerning the latest version of graphql-yoga we'll close it.
Feel free to reopen it at any time if you believe we should futher discuss its content. :slightly_smiling_face:

Was this page helpful?
0 / 5 - 0 ratings