Graphql-yoga: getRemoteSchema - function proposal

Created on 14 Dec 2017  路  5Comments  路  Source: dotansimha/graphql-yoga

I think it would be useful to have such function in graphql-yoga:

export async function getRemoteSchema(uri) {
    const link = new HttpLink({ uri, fetch })
    const introspectionSchema = await introspectSchema(link);
    const graphcoolSchema = makeRemoteExecutableSchema({
        schema: introspectionSchema,
        link
    });

    return graphcoolSchema;
}

To create easily remote schemas and merge them all.

What do you think?

Most helpful comment

@schickling I've created new project @jokio/graphql, it's graphql server, built on top of graphql-yoga. This package will solve my domain specific problems, but for now there are more generic solutions.

Here is the example of complex scenario:

  • stitch remote schemas
  • split your local code to multiple little schemas
  • working with rest apis

example: https://github.com/jokio/graph/blob/master/src/index.ts

Please check out and if you will like any ideas I can send pull request.

Discussion

I've found two main issues while I was developing my package and I want to discuss:

  1. I need this code to be async, because I'm going to make authentication if user will enable it.

  2. graphql-yoga creates context for web sockets per operation (onOperation) and I need it to be created only once when user connects (onConnect), based on connectionParams. What was the reason of using onOperation?

All 5 comments

While I think it's a relatively common use case, I'd still be very interested what your concrete use case is. As there are more and more GraphQL bindings for public GraphQL APIs (like this Github API binding) this would be another solution for many use cases.

My use case is to have graphql micro-services: Users, Roles, Game1, Game2, Payments and to stitch them together like that: (urls are mock)

const usersSchema = await getRemoteSchema('https://users.jok.io/graphql');
const rolesSchema = await getRemoteSchema('https://roles.jok.io/graphql');
const game1Schema = await getRemoteSchema('https://game1.jok.io/graphql');
const game2Schema = await getRemoteSchema('https://game2.jok.io/graphql');
const paymentsSchema = await getRemoteSchema('http://payments.jok.io/graphql');

const typeDefs = `...`
const resolvers = {...}

const schema = mergeSchemas({
  schemas: [usersSchema, rolesSchema, game1Schema, game2Schema, paymentsSchema, typeDefs],
  resolvers: resolvers
});

...

I see, to me it sounds like this functionality would be a better fit as part of graphql-tools as you're using mergeSchemas anyway. Maybe you want to open an issue/PR over there?

Okey thanks, I've one idea I'll share it later!

@schickling I've created new project @jokio/graphql, it's graphql server, built on top of graphql-yoga. This package will solve my domain specific problems, but for now there are more generic solutions.

Here is the example of complex scenario:

  • stitch remote schemas
  • split your local code to multiple little schemas
  • working with rest apis

example: https://github.com/jokio/graph/blob/master/src/index.ts

Please check out and if you will like any ideas I can send pull request.

Discussion

I've found two main issues while I was developing my package and I want to discuss:

  1. I need this code to be async, because I'm going to make authentication if user will enable it.

  2. graphql-yoga creates context for web sockets per operation (onOperation) and I need it to be created only once when user connects (onConnect), based on connectionParams. What was the reason of using onOperation?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lautiamkok picture lautiamkok  路  4Comments

ahmedosama5200 picture ahmedosama5200  路  4Comments

kv-pawar picture kv-pawar  路  3Comments

checkmatez picture checkmatez  路  5Comments

woss picture woss  路  5Comments