- Notifications
You must be signed in to change notification settings - Fork0
argemiront/vanjs-graphql
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Code for the talk on VanJS meetup about GraphQL.
- npm
- git
- node
To set up the code you will need to pull down the source codes from github repo as follows:
cd~git clone https://github.com/argemiront/vanjs-graphql.gitcd vanjs-graphqlnpm install
You can serve the API at your local machine onhttp://localhost:3000
. To start serving the API,
npm start
You can change the port on theindex.js
from the root folder of the project in the following line:
server.listen({ port: 3000 }).then(({ url }) => console.log(`serving at: ${url}`));
Basic structure with schema, resolvers and server inside theindex.js
file.
Thegraphql
folder is created. Schemas and its resolvers now are in separated folders.
Themerge-graphql-schemas library is used to automatically merge schemas and resolvers inside the folder that follows the pattern:
- schemas:schema_name.typedefs.gql
- resolvers:resolver_name.resolvers.js
The data is moved to thedatabase.js
lib inside theutils
folder. It provides functions to fetch the data.
Middleware are added to the project in 3 different ways:
- added in the GraphQL context for authentication purpose;
- to run with all resolvers;
- to run before a specific resolver;
Middleware are merged with the original schema and resolvers by theapplyMiddleware
functions from thegraphql-middleware library.
Thedataloader middleware is added here to batch and cache database requests.
The branch has two parts, on4.1 it is only added aconsole.log
on the database library to demonstrate the issue with multiple data load. On4.2 the issue is solved by applying the dataloader.
In the last part two directives are created to perform additional computation on the server before the data is sent to the client.
Creating a new directive can be accomplished with the following procedures:
- add the directive to the schema
- extend theSchemaDirectiveVisitor class
- override the desired visitor method
About
Code from the VanJS talk about GraphQL
Resources
Uh oh!
There was an error while loading.Please reload this page.