prisma-labs / prisma-binding

GraphQL Binding for Prisma 1 (using GraphQL schema delegation)
https://www.prisma.io/docs/prisma-graphql-api/prisma-bindings/prisma-bindings-prb1/
MIT License
476 stars 44 forks source link

support for multiple services? #75

Closed terion-name closed 5 years ago

terion-name commented 6 years ago

One great feature with graphql is that one can combine multiple apis in one, with schema stitching or weaver schemas. The same applies here: one could have multiple underlying prisma services (with different contexts and/or different types of db) and it would be great to in single binder, something like this:

const prisma = new Prisma([
{
  typeDefs: 'schemas/sql_database.graphql',
  endpoint: 'https://us1.prisma.sh/demo/my-service1/dev'
  secret: 'my-super-secret-secret'
},
{
  typeDefs: 'schemas/neo4j_database.graphql',
  endpoint: 'https://us1.prisma.sh/demo/my-service2/dev'
  secret: 'my-super-secret-secret'
}
])

This comes from a real-world necessity and I thing some other people would also benefit from this

kbrandwijk commented 6 years ago

What you could currently do if you manage your Prisma backends outside of your Graphl Server project, is use prisma-bindings and add the Prisma backends as regular endpoints (so without the prisma extension in the config). That way, they would behave like any other endpoint. It would allow you to add two Prisma bindings to your context. Is your example, you are adding two endpoints to a single binding, but I don't see any benefit over using two bindings.

a-type commented 6 years ago

I have a use case that involves multiple Prisma APIs to bind against. After trying to create two separate Prisma objects in context, I noticed that they both ended up pointing to the same schema and endpoint. If I understand the conversation correctly so far, that means @kbrandwijk 's suggestion will not behave as expected.

The problem appears to be rooted in the global variable for remoteSchema https://github.com/graphcool/prisma-binding/blob/2117ddffdad990867616505ef80f618e4628a21d/src/Prisma.ts#L16. If I construct a Prisma pointed at a particular schema, then a second one, both instances will use the first schema provided due to the check on line 59 https://github.com/graphcool/prisma-binding/blob/2117ddffdad990867616505ef80f618e4628a21d/src/Prisma.ts#L59.

I haven't used TypeScript before, but I could try to put in a patch. Changes were introduced in https://github.com/graphcool/prisma-binding/commit/67612e9505a97032489238a7db55fbf20b47f9e0; any fix would probably benefit from understanding why the remote schema caching was changed.

kbrandwijk commented 6 years ago

@a-type That is a very good point, thank you for bringing this up. I have created https://github.com/graphcool/prisma-binding/issues/81 for this.

schickling commented 6 years ago

@a-type would you be open creating a PR for this (see #81)?

a-type commented 6 years ago

@schickling Sure, I'll look into doing that soon. Be advised that I've never written Typescript before, but hopefully this is a fairly trivial change.

maticzav commented 5 years ago

Fixed with #81