Skip to content

Instantly share code, notes, and snippets.

import express from 'express';
import Schema from './data/schema';
import Resolvers from './data/resolvers';
// import Mocks from './data/mocks';
import { apolloExpress, graphiqlExpress } from 'apollo-server';
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import bodyParser from 'body-parser';
const GRAPHQL_PORT = 8080;
# mutation to add a reaction:
mutation test($input: AddReactionInput!){
addReaction(input: $input){
reaction {
content
}
}
}
# the variables (paste those in the bottom textarea)
@helfer
helfer / apollo-server-tracer.js
Last active October 22, 2016 15:30
How to instrument apollo server 0.2 with tracer
import express from 'express';
import { Tracer } from 'graphql-tracer';
import { apolloExpress } from 'apollo-server';
import Schema from './schema';
const app = express();
const tracer = new Tracer({ TRACER_APP_KEY: '...'});
addTracingToResolvers(Schema);
// at the top with imports:
import Mongoose from 'mongoose';
// somewhere in the middle:
const mongo = Mongoose.connect('mongodb://localhost/views');
const ViewSchema = Mongoose.Schema({
postId: Number,
views: Number,
});
@helfer
helfer / apolloHAPI.js
Last active March 7, 2017 12:44
Using Apollo Server with HAPI
import hapi from 'hapi';
import graphql from 'graphql';
import { ApolloHAPI } from 'apollo-server';
const myGraphQLSchema = new graphql.GraphQLSchema({
// define your schema in GraphQL.js syntax here ...
});
const server = new hapi.Server();
@helfer
helfer / apollo-1-migration.md
Last active May 31, 2017 01:09
Migrating from Apollo Client 0.x to 1.0

Migrating from Apollo Client 0.x to 1.0

Here are the main breaking changes between the 0.x and 1.0 versions of Apollo Client.

fetchMore

The structure of fetchMoreResult has been changed. Previously fetchMoreResult used to contain data and loading fields, now fetchMoreResult is what fetchMoreResult.data used to be. This means your updateQueries function has to change as follows:

updateQuery: (prev, { fetchMoreResult }) => {
@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
}
// 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-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 {
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', {