Skip to content

Instantly share code, notes, and snippets.

# Autogenerated input type of AddComment
input AddCommentInput {
# A unique identifier for the client performing the mutation.
clientMutationId: String
# The Node ID of the subject to modify.
subjectId: ID!
# The contents of the comment.
body: String!
// > npm install graphql-tools
import { mockServer } from 'graphql-tools';
import schema from './mySchema.graphql';
const myMockServer = mockServer(schema);
myMockServer.query(`{
allUsers: {
id
name
const resolvers = {
Query: {
author(root, args){
return { id: 1, firstName: 'Hello', lastName: 'World' };
},
},
Author: {
posts(author){
return [
{ id: 1, title: 'A post', text: 'Some text', views: 2},
import { mockServer, MockList } from 'graphql-tools';
import casual from 'casual-browserify';
// The GraphQL schema. Described in more detail here:
// https://medium.com/apollo-stack/the-apollo-server-bc68762e93b
const schema = `
type User {
id: ID!
name: String
// add this import at the top
import fetch from 'node-fetch';
// add this somewhere in the middle
const FortuneCookie = {
getOne() {
return fetch('http://fortunecookieapi.herokuapp.com/v1/cookie')
.then(res => res.json())
.then(res => {
return res[0].fortune.message;
/**
* lagRadar
* Licence: ISC copyright: @mobz 2018
*/
window.lagRadar = function lagRadar( config = {} ) {
const {
frames = 50, // number of frames to draw, more = worse performance
speed = 0.0017, // how fast the sweep moves (rads per ms)
size = 300, // outer frame px
import Sequelize from 'sequelize';
import casual from 'casual';
import _ from 'lodash';
const db = new Sequelize('blog', null, null, {
dialect: 'sqlite',
storage: './blog.sqlite',
});
const AuthorModel = db.define('author', {
@helfer
helfer / apollo-server-tutorial-schema.js
Last active February 28, 2018 04:38
The full schema for the GraphQL server tutorial
import { makeExecutableSchema } from 'graphql-tools';
const typeDefs = `
type Author {
id: Int
firstName: String
lastName: String
posts: [Post]
}
type Post {
// customize mocking per type (i.e. Integer, Float, String)
mockServer(schema, {
Int: () => 6,
Float: () => 22.1,
String: () => 'Hello',
});
// customize mocking per field in the schema (i.e. for Person.name and Person.age)
mockServer(schema, {
@helfer
helfer / apollo-starter-kit-schema.js
Last active June 23, 2017 04:50
GraphQL schema in the apollo-starter-kit
import {
makeExecutableSchema,
addMockFunctionsToSchema,
} from 'graphql-tools';
import mocks from './mocks'
const typeDefs = `
type Query {
testString: String
}