question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

server example with modules

See original GitHub issue

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,
  ...

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kissmygrittscommented, Mar 21, 2018

@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.

0reactions
jboothecommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server module example | Drupal.org
Here is a commented example of a server module which uses hook_server() to become a server.
Read more >
Building a server module — Group-Office documentation
The package is a group of modules that belong to each other. It is used to group modules per type or per customer....
Read more >
Mapping modules to servers - IBM
You can map modules of an application or stand-alone Web module to one or more target servers during or after application installation using...
Read more >
How To Create a Web Server in Node.js with the HTTP Module
First, we'll create an HTML file that the web server will return. Create a new HTML file: touch index.
Read more >
Developing modules for the Apache HTTP Server 2.4
sum, the server will let all modules know, that this request should be served by "example-handler ". As you will see later, when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found