What is the best way to structure a graphQL project/server side? this is my current structure
config
models
src
schema
Product
model.js
query.js
mutation.js
type.js
resolvers.js
index.js
Order
query.js
mutation.js
model.js
types.js
resolvers.js
index.js
index.js
let's explore what's inside the Product directory
query.js: all the query resolvers related to the Product
mutations.js: all the mutation resolvers related to the Product
types.js: all the Product related GraphQL types also query and mutation included (export a string containing GraphQL types).
mode.js: the Product database schema.
resolvers.js: all the resolvers related to the Product type. e.g:
let Product = {
comments: (user: id) => {
// whatever
}
}
Product/index.js: combine all the files and export them as Query, Mutation, types, Product (Product type fields resolvers).
Note: you can also convert query.js or any one of them to a folder and then write each query and mutation resolver in its own file.
schema/index.js: combine all the exported Query, Mutation, type inside index.js and export them as resolvers and typeDefs
e.g
export const resolvers = {
Query: {
...ProductQueries,
...OrderQueries,
},
Mutation: {
...ProductQueries,
...OrderMutations,
},
// schema/Proudct/resolvers.js
Product,
Order
}
For a complete description follow this link https://theehsansarshar.hashnode.dev/scalable-graphql-architecture
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With