Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Code from the VanJS talk about GraphQL

NotificationsYou must be signed in to change notification settings

argemiront/vanjs-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Code for the talk on VanJS meetup about GraphQL.

Prerequisites

  • npm
  • git
  • node

Installation

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

Starting Local Server

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}`));

Branches

1.basic

Basic structure with schema, resolvers and server inside theindex.js file.

2.folders

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.

3.middleware

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.

4.dataloader

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.

5.directives

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

Further Reading

About

Code from the VanJS talk about GraphQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp