Created
August 24, 2016 05:55
-
-
Save voodooattack/76bc617f279caf3dd59a8ed235207c7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GraphQLSchema } from 'graphql/type'; | |
import { graphql } from 'graphql'; | |
import { type, query, mutation, field, iface, Schema } from '../src'; | |
class MySchema extends Schema { } | |
/** | |
* Declare a basic interface | |
*/ | |
@iface(MySchema) | |
class Node { | |
@field('ID!') | |
id = 1; | |
} | |
/** | |
* Declare the type 'User', it automatically inherits everything from Node. | |
*/ | |
@type(MySchema) | |
class User extends Node | |
{ | |
@field('String!') | |
username = 'Abdullah'; | |
@field('String!') | |
password = 'Secret!'; | |
@field('[User]') | |
friends; | |
} | |
@type(MySchema) | |
class Query { | |
@query('viewer : User') | |
async viewer() { return new User(); } | |
} | |
@type(MySchema) | |
class Mutation { | |
@mutation('signUp(username: String!, password: String!): ID') | |
async signUp({ username, password}) { return 1; } | |
} | |
const schema = new MySchema(); | |
const theSchema = new GraphQLSchema({ query: schema.getType('Query'), mutation: schema.getMutationType() }); | |
graphql(theSchema, `query { viewer { id } }`) | |
.then(r => console.log(r)).catch(console.error); | |
graphql(theSchema, `mutation { signUp(username: "test1", password: "test2") }`) | |
.then(r => console.log(r)).catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment