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 / mutation.js
Created April 19, 2017 06:35
Relay Modern mutation example
const mutation = graphql`
mutation MarkReadNotificationMutation(
$input: MarkReadNotificationData!
) {
markReadNotification(data: $input) {
notification {
seenState
}
}
}
@stubailo
stubailo / query-renderer.js
Created April 19, 2017 08:32
A snippet of the query renderer from the hello world relay modern app
<QueryRenderer
environment={environment}
query={graphql`
query AppFeedQuery {
feed (type: NEW, limit: 5) {
repository {
owner { login }
name
stargazers_count
@stubailo
stubailo / fetch-graphql.js
Created September 5, 2017 08:15
Call a GraphQL API with fetch
require('isomorphic-fetch');
fetch('https://1jzxrj179.lp.gql.zone/graphql', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: '{ posts { title } }' }),
})
.then(res => res.json())
.then(res => console.log(res.data));
@stubailo
stubailo / apollo-fetch.js
Last active December 1, 2018 15:54
Call a GraphQL API with apollo-fetch
const { createApolloFetch } = require('apollo-fetch');
const fetch = createApolloFetch({
uri: 'https://1jzxrj179.lp.gql.zone/graphql',
});
fetch({
query: '{ posts { title }}',
}).then(res => {
console.log(res.data);
@stubailo
stubailo / query.js
Last active October 18, 2017 03:18
Apollo Client query
export default graphql(gql`{
feed(type: TOP, limit: 10) {
repository {
name
owner { login }
}
postedBy { login }
}
}`)(props => (
<List>
@stubailo
stubailo / mutation.js
Last active January 31, 2018 20:03
Apollo Client mutation
export default graphql(gql`
mutation submitRepository($repoFullName: String!) {
submitRepository(repoFullName: $repoFullName) {
createdAt
}
}
`)(props => (
<button
onClick={() => {
// Mutate function passed via props
@stubailo
stubailo / schema.js
Created October 22, 2017 18:21
Hello world with graphql-tools
const { makeExecutableSchema } = require('graphql-tools');
const typeDefs = `
type Query {
books: [Book]
}
type Book {
title: String
author: String
}
@stubailo
stubailo / server.js
Last active March 12, 2018 15:13
Engine setup with Apollo Server
// Install and import the apollo-engine package
const { ApolloEngine } = require('apollo-engine');
const { graphqlExpress } = require('apollo-server-express');
const app = express();
// Enable tracing and cacheControl in Apollo Server
app.use('/graphql', graphqlExpress({
tracing: true,
cacheControl: true,
@stubailo
stubailo / engine.json
Created March 13, 2018 20:15
Engine config with caching
{
"apiKey": "TODO",
"origins": [
{
"lambda": {
"functionArn": "TODO",
"awsAccessKeyId": "TODO",
"awsSecretAccessKey":"TODO"
}
}
@stubailo
stubailo / schema.js
Last active March 13, 2018 22:52
Ticketmaster schema
// Construct a schema, using the GraphQL schema language
const typeDefs = gql`
type Query {
myFavoriteArtists: [Artist]
}
type Artist @cacheControl(maxAge: 60) {
id: ID
name: String
image: String