Skip to content

Instantly share code, notes, and snippets.

View stubailo's full-sized avatar
📈
Working on Flipturn!

Sashko Stubailo stubailo

📈
Working on Flipturn!
View GitHub Profile
const { buildClientSchema } = require("graphql");
const fs = require("fs");
const introspectionSchemaResult = JSON.parse(fs.readFileSync("result.json"));
const graphqlSchemaObj = buildClientSchema(introspectionSchemaResult);
const { printSchema } = require("graphql");
console.log(printSchema(graphqlSchemaObj));
const { makeExecutableSchema } = require("graphql-tools");
const sdlSchema = `
type Author {
firstName: String
lastName: String
}
type Query {
author(id: Int!): Author
const { buildSchema } = require('graphql');
const sdlSchema = `
type Author {
firstName: String
lastName: String
}
type Query {
author(id: Int!): Author
const {
GraphQLObjectType,
GraphQLSchema,
GraphQLNonNull,
GraphQLInt
} = require("graphql");
const queryType = new GraphQLObjectType({
name: "Query",
fields: {
@stubailo
stubailo / result.json
Created May 15, 2018 23:43
Introspection query result
{
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": {
"name": "Mutation"
},
"subscriptionType": null,
"types": [
users: (root, args, context) => {
// In this case, we'll pretend there is no data when
// we're not logged in. Another option would be to
// throw an error.
if (!context.user) return [];
return ['bob', 'jake'];
}
@stubailo
stubailo / merge.js
Created April 26, 2018 05:39
Schema merging with delegation to underlying schema
import {
transformSchema,
mergeSchemas,
FilterRootFields,
RenameTypes,
RenameRootFields,
} from 'graphql-tools';
// Transform the schema to namespace it and only keep one root field
const transformedChirpSchema = transformSchema(chirpSchema, [
@stubailo
stubailo / engine.js
Last active March 20, 2018 18:05
Engine
const engine = new ApolloEngine({
apiKey: process.env.ENGINE_API_KEY
});
// Start the server
engine.listen({
port: PORT,
expressApp: app
}, () => {
console.log(`Go to http://localhost:${PORT}/graphiql to run queries!`);
@stubailo
stubailo / server.js
Last active March 13, 2018 22:56
Middleware
// The GraphQL endpoint
app.use(
"/graphql",
bodyParser.json(),
graphqlExpress({
schema,
tracing: true,
cacheControl: true,
context: {
secrets: {