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
@stubailo
stubailo / graphql-tools.js
Last active November 26, 2018 17:08
Quickly mocking a schema with graphql-tools
import {
makeExecutableSchema,
addMockFunctionsToSchema
} from 'graphql-tools';
import { graphql } from 'graphql';
// Fill this in with the schema string
const schemaString = `
type Todo { id: ID, text: String, completed: Boolean }
type User { id: ID, name: String }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Sort reverse</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@stubailo
stubailo / api.diff
Created August 13, 2018 23:19
Add dog photo
const typeDefs = gql`
type Query {
hello: String
+ dogPhotoUrl: String
}
`;
const resolvers = {
Query: {
hello: (root, args, context) => {
@stubailo
stubailo / query.diff
Created August 13, 2018 23:18
Add dog photo
<Query
query={gql`
{
hello
+ dogPhotoUrl
}
`}
>
- {({ data }) => <div>A greeting from the server: {data.hello}</div>}
+ {({ data }) => (
@stubailo
stubailo / graphql.js
Last active August 6, 2019 22:57
Apollo Server Lambda hello world
// src/lambda/graphql.js
const { ApolloServer, gql } = require("apollo-server-lambda");
const typeDefs = gql`
type Query {
hello: String
}
`;
const resolvers = {
@stubailo
stubailo / index.html
Created June 28, 2018 08:49 — forked from gaearon/index.html
Add React in One Minute
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Add React in One Minute</title>
</head>
<body>
<h2>Add React in One Minute</h2>
<p>This page demonstrates using React with no build tooling.</p>
const fetch = require("node-fetch");
const { introspectionQuery } = require("graphql");
const fs = require("fs");
fetch("https://1jzxrj179.lp.gql.zone/graphql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query: introspectionQuery })
})
.then(res => res.json())
const { buildClientSchema, printSchema } = require("graphql");
const fs = require("fs");
const introspectionSchemaResult = JSON.parse(fs.readFileSync("result.json"));
const graphqlSchemaObj = buildClientSchema(introspectionSchemaResult);
const sdlString = printSchema(graphqlSchemaObj);
const { buildSchema, graphqlSync, introspectionQuery } = require("graphql");
const sdlString = `
type Query {
hello: String
}
`;
const graphqlSchemaObj = buildSchema(sdlString);
const result = graphqlSync(graphqlSchemaObj, introspectionQuery).data;
const { graphqlSync, introspectionQuery } = require("graphql");
const result = graphqlSync(graphqlSchemaObj, introspectionQuery).data;