Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server example with modules #136

Closed
beebase opened this issue Jan 23, 2018 · 7 comments · Fixed by #224
Closed

server example with modules #136

beebase opened this issue Jan 23, 2018 · 7 comments · Fixed by #224
Assignees

Comments

@beebase
Copy link

beebase commented Jan 23, 2018

I was trying to use achieve this with
https://github.com/okgrow/merge-graphql-schemas
but I'm not sure if that's the right direction. There seem to be many ways to structure graphql servers.
Would be nice if one of the yoga server examples would show how to set up a modularised structure in front of the prisma API

+-- src
|   +-- types
|   |   +-- index.js (grouped types)
|   |   +-- auth.graphql (imports from prisma api)
|   |   +-- post.graphql (imports from prisma api)
|   +-- resolvers
|   |   +-- index.js (grouped resolvers)
|   |   +-- auth.js 
|   |   +-- post.js 
|   + index.js (server)

src/index.js (server)

const resolvers = require('./resolvers')
const typeDefs = require('./types')
const server = new GraphQLServer({
  typeDefs,
  resolvers,
  ...
@kbrandwijk kbrandwijk changed the title [question] server example with modules server example with modules Jan 28, 2018
@microvn
Copy link

microvn commented Jan 29, 2018

Refer

apollographql/apollo-server#43

Hope it helps you

@beebase
Copy link
Author

beebase commented Jan 29, 2018

I still don't see a decent solution for modularization with .graphql files.
At this point I would choose:
https://www.apollographql.com/docs/graphql-tools/generate-schema.html#modularizing
However the prisma API generates .grahpql files which I need to import into post.graphql (post.graphql, auth.graphql are modules replacing the grand schema.graphql)

# import {Post} from '../generated/prisma.graphql
...

I tried https://github.com/okgrow/merge-graphql-schemas to merge the module files (auth, post)
into one schema, but it ignores # import statements

@jboothe
Copy link
Contributor

jboothe commented Mar 16, 2018

@beebase Did you ever find a solution for modularization with graphql-yoga?

@kissmygritts
Copy link

@beebase why do you need to import post.graphql? Merging the schema will take care of this into a single schema declaration for the GraphQLServer command behind the scenes in graphql-yoga.

Based on your comments above it sounds like you have two directories with .graphql files? One with user defined schema, and a second with prisma defined schema.

// ... other code
const typesArray = [...fileLoader(path.join(__dirname, './userDefinedSchemaFolder'), ...fileLoader(path.join(__dirname, './prismaSchemaFolder')]
const typeDefs = mergeTypes(typesArray, { all: true })

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

If I am misunderstanding you and there truly is only one folder of schema definitions, then my initial statement will work. You do not need to import schema definitions into files that references that schema. merge-graphql-schemas creates a concatenated type definition that contains all the references. This concatenated (merged) type definition can then be passed to the GraphQLServer call. The code below has worked for me, give it a shot.

const { fileLoader, mergeTypes, mergeResolvers } = require('merge-graphql-schemas')

const typesArray = fileLoader(path.join(__dirname, './types')
const typeDefs = mergeTypes(typesArray, { all: true })

const resolversArray = fileLoader(path.join(__dirname, './resolvers')
const resolvers = mergeResolvers(resolversArray)

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

Let me know if that works, or you have question. I don't use prisma so I am not familiar with the api or directory structure.

@jboothe
Copy link
Contributor

jboothe commented Mar 21, 2018

I have not been able to get merge-graphql-schemas to work with graphql-yoga. See #214

@beebase
Copy link
Author

beebase commented Mar 21, 2018

@jboothe @kissmygritts I paused my graphql project since my post end January. I was hitting a wall trying to modularise prisma. Tried different approaches but none of them worked for me. Couldn't find any example code either.

@jboothe
Copy link
Contributor

jboothe commented Mar 21, 2018

Yeah, if I knew how to solve it I would gladly submit a PR example project. I find it hard to believe someone has not solved this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants