A central graphql server for dailyos apps.
Clone the repo and install packages:
git clone https://github.com/dailykit/data-hub.git
cd data-hub
yarn
src
| - index.js
| +- models
| | - index.js
| | - recipe.js
| +- schema
| | +- mutations
| | | - index.js
| | +- queries
| | | - index.js
| | +- recipes
| | | - types.js
| | | - index.js
| | | - resolvers.js
| | - index.js
- All the mongoose schema models goes inside
models
folder, create a new file for your entity. - Import the schema model inside
models/index.js
file. - User the existing models as reference while creating your own.
- Models are already available through
context
const resolvers = {
Query: {
recipes: async (parent, args, { models }) => {
const { Recipe } = models
const recipes = await Recipe.find()
return recipes
}
}
}
- All the queries goes inside
schema/queries/index.js
file. - Group your queries by entity type and leave a empty line before other entities. e.g:
type Query {
recipes: [Recipe]
recipe(id: ID!): Recipe
ingredients: [Ingredient]
ingredient(id: ID!): Ingredient
}
- All the mutations goes inside
schema/mutations.index.js
file. - Group your mutations by entity type and leave a empty line before other entities same as queries.
- Before writing your mutations, extend the
MutationResponse
interface and add the entity name and type as a field. - Check the current
index.js
file in mutations for reference. - Then go into
responses/index.js
and add anelse if
condition and follow the existingif
condition.
- Same as
schema/recipes
folder, create one for your entity and add theindex.js
,types.js
andresolvers.js
file in the folder.