Express-graphql: Folder structure

Created on 8 Oct 2015  路  17Comments  路  Source: graphql/express-graphql

I was working this graphql and express and reach the moment than I can not hold all fields definitions in schema.js, so I tried to create the folder structure for this case. Which you can reach by link.
I would be glad to discuss this question. Thank you.

discussion

Most helpful comment

I'm satisfied with this:
screen shot 2015-11-15 at 6 38 45 pm
I call schema with require('./schema').

All 17 comments

Thanks for sharing! While throwing everything in a single schema.js file is a great way to get started, it's true that it becomes unwieldy as the schema grows. You example definitely goes a long way towards imposing order.

Have you tried discussing this with other people on the Slack channel? I expect that others are probably exploring this question just like you are, and it would be interesting to share opinions.

@wincent I did not discuss this on the Slack, but it's good idea. Thank you.

@sulliwane what if you have more complex schema?

I'm satisfied with this:
screen shot 2015-11-15 at 6 38 45 pm
I call schema with require('./schema').

For example you have next query, which can grow up in future. Will you write all queries in one query file?

query {
 viewer {
  users (first: 10) {
   name,
   address {
    street,
    building,
    neighbors {
     firstName,
     lastName
    }
   }
  } 
 }
}

@mikhail-riabokon I create a file for each query that queries the database.

@xpepermint your variant is better than mine. Thank you. But I use not only one file for queries.

-- mutations
----- .......
-- types
----- ....
-- queries
----- root.js
----- queries
--------- queryField
------------ index.js
------------ ....
--------- ......

It make's queries more structured, and it's really help me with "queries mess".

I've updated an example for better understanding.

Sorry for my misunderstanding, is there a question or issue raised here? I'm not sure what you would like from me or this repo.

My personal opinion is that splitting large schema up across many files is a good idea and something I would encourage.

The reason the example in this repo builds a schema in a single file is because it is quite small and I wanted to keep the example simple.

@leebyron Actually I have asked about folder structure because it's hard to keep everything in one file. That's why we have discussed that, and @xpepermint gave good example and I have updated my, with more than "one level" of queries. So for now, I think this question can be closed, if you do not have any suggestions. Thank you.

Okay great.

@xpepermint hello how do you do to join the queries in a single object "GraphQLObjectType"

@ahelord Just use the usual require commands and make sure you set fields: () => ({}) (a method that returns fields object).

@xpepermint I'm sorry, do not ask well.

How do you assemble all the graphql query files in another file to parse the object GraphQLObjectType

@mykhailo-riabokon hi

you could have this project

https://github.com/mykhailo-riabokon/express_graphql_folder_structure

run with Express

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmytro-kerest picture dmytro-kerest  路  3Comments

macin40 picture macin40  路  4Comments

m-diiorio picture m-diiorio  路  4Comments

naivefun picture naivefun  路  3Comments

justinmchase picture justinmchase  路  4Comments