graphql-fullstack
Experimental GraphQL-oriented web framework.
Inspired by https://github.com/nuwave/lighthouse
Install
npm install --save graphql-fullstack
Or if you use Yarn:
yarn add graphql-fullstack
Getting Started
First, write your schema and resolver:
schema.graphql
type Query { hello: String @field(resolver: "hello")}
resolvers/hello.js
module 'world'
Then run GraphQL server:
npx graphql-fullstack serve --schema schema.graphql# => running on http://localhost:5252
Now you can request GraphQL:
curl -XPOST localhost:5252/graphql -d query='query Hello { hello }'
returns
Directives
GraphQL-Fullstack will have various kind of directives.
@create
Create given model type from input
variables.
type User { id: String! name: String} input UserInput { name: String} type Mutation { createUser(input: UserInput!): User @create(type: User)}
@all
Read all data of given model type.
type User { id: String! name: String} type Query { users: [User] @all(type: User)}
@field
Manually resolve a field. resolver
argument is the file name of the resolver. It defaults to ./resolvers
, but you can change it by config file (see below).
type User { id: String! name: String} type Query { user: User @field(resolver: 'UserResolver')}
Config
You can change the path of your project.
Create graphql.config.js
file and run npx graphql-fullstack
with -c
or --config
option.
const resolve = moduleexports = basePath: // Resolver search paths. resolvers: // By default, $PWD/resolvers is set, but you can set other resolver paths.
npx graphql-fullstack -c graphql.config.js
CRUD example
type User { id: String! name: String} input UserInput { name: String} type Query { users: [User] @all(type: User)} type Mutation { createUser(input: UserInput!): User @create(type: User)}
Roadmap
- Basic GraphQL features
- Resolver
- Input type
- Use MongoDB to store relational data [opinionated]
- create
- read
- all
- find
- where
- update
- delete
- Middleware