VulcanJS / Vulcan

🌋 A toolkit to quickly build apps with React, GraphQL & Meteor
http://vulcanjs.org
MIT License
7.98k stars 1.89k forks source link

load graphql schemas from .graphql files #1926

Open macrozone opened 6 years ago

macrozone commented 6 years ago

using https://github.com/Swydo/meteor-graphql you can load .graphql files in meteor applications.

this returns directly something that can be used in makeExecutableSchema.

unfortunatly, it does not play nice with vulcan, as there is no api to add these kind of typedefs.

Any way to use graphql files?

SachaG commented 6 years ago

Since Vulcan already takes strings and adds them to the schema I think it should work out of the box without that package. Have you tried it?

See http://docs.vulcanjs.org/graphql-schema.html#Custom-Schemas

SachaG commented 6 years ago

(Use addGraphQLSchema() btw, the docs are a little bit out of date)

macrozone commented 6 years ago

@SachaG yes, i use that currently:

// ...
import MySchema from './MySchema.graphql';

addGraphQLSchema(MySchema.loc.source.body);

But this has some downsides (compared to the normal usage of swydo:graphql):

would be cool beeing able to use

import MySchema from './MySchema.graphql';

addGraphQLSchema(MySchema);

MySchema is an object of the shape

{
"kind": "Document",
"definitions": [
  {
    "kind": "ObjectTypeDefinition",
    "name": {
      "kind": "Name",
      "value": "MyField"
    },
    // ...
    ]
  },
  // ...

so this definition list could maybe be merged with the parsed default schema that vulcan generates

SachaG commented 6 years ago

The thing is, I don't know if makeExecutableSchema can accept multiple typeDefs? If not we'd need a way to merge different schema objects together but I don't really know how to do that…

vincro commented 6 years ago

Was at a @formidablelabs workshop recently and they mentioned @okgrow merge schema tool:

https://github.com/okgrow/merge-graphql-schemas

SachaG commented 6 years ago

Oh interesting. @macrozone maybe you can give that a try? Here's where the magic happens:

https://github.com/VulcanJS/Vulcan/blob/devel/packages/vulcan-lib/lib/server/apollo_server.js#L204-L226

(The weird formatting is to ensure the schema comes out right when you want to log it out)

MathiasKandelborg commented 6 years ago

Apollo also has a mergeSchema function

On Tue, Mar 13, 2018, 14:24 Sacha Greif notifications@github.com wrote:

Oh interesting. @macrozone https://github.com/macrozone maybe you can give that a try? Here's where the magic happens:

https://github.com/VulcanJS/Vulcan/blob/devel/packages/vulcan-lib/lib/server/apollo_server.js#L204-L226

(The weird formatting is to ensure the schema comes out right when you want to log it out)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/VulcanJS/Vulcan/issues/1926#issuecomment-372663428, or mute the thread https://github.com/notifications/unsubscribe-auth/AfguWx1qOo0OoyMSIr6_bzfQAF1x0OeVks5td8iEgaJpZM4Sod6c .

vincro commented 6 years ago

Maybe we can end up with 3 PRs for different solutions :) HAHAHA @MathiasKandelborg wins!

SachaG commented 6 years ago

There's also https://github.com/creditkarma/graphql-loader which I think can merge schemas?