Skip to content

Instantly share code, notes, and snippets.

// Start imports for React Apollo GraphQL Queries
import { ApolloProvider } from 'react-apollo';
import { ApolloClient } from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
// End of imports for React Apollo GraphQL Queries
// Start imports for GraphQL Hooks Queries
import { GraphQLClient, ClientContext } from 'graphql-hooks';
import memCache from 'graphql-hooks-memcache';
const api = require('./server/api');
const typeDefs = require('./server/schema');
const resolvers = {
Query: {
countries: () => api.countries,
country: (obj, args) => {
for (const record of api.countries) {
if (record.id === args.id) {
return record;
const { gql } = require('apollo-server');
const typeDefs = gql`
type Country {
name: String!
population: String!
inNato: Boolean!
id: Int!
}
@bartcis
bartcis / graphql_component.js
Created July 17, 2019 13:51
Example component with GraphQL query
import React, { Component } from 'react';
import '../styles/App.css';
import { Query } from 'react-apollo'
import gql from 'graphql-tag'
const countiresQuery = gql` {
countries {
name
population
@bartcis
bartcis / graphql_query_react.js
Created July 17, 2019 13:46
Define simple query in graphQL
import { Query } from 'react-apollo'
import gql from 'graphql-tag'
const countiresQuery = gql` {
countries {
name
population
inNato
}
}`
@bartcis
bartcis / react_apollo_integration.js
Created July 17, 2019 13:42
Simple integration of React and Apollo
import React from 'react';
import ReactDOM from 'react-dom';
import './styles/index.css';
import App from './components/App';
import * as serviceWorker from './serviceWorker';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient } from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
@bartcis
bartcis / example_resolvers.js
Created July 17, 2019 13:06
Simple resolvers for GraphQL
const resolvers = {
Query: {
books: () => api.books,
countries: () => api.countries
},
};
@bartcis
bartcis / schema_definition.js
Created July 17, 2019 12:53
GraphQL schema excercise
const { gql } = require('apollo-server');
const typeDefs = gql`
type Book {
title: String
author: String
}
type Country {
name: String
population: String
@bartcis
bartcis / schema_import.js
Created July 17, 2019 12:52
Import of GraphQL schemas - excercise
// Import of the file where we build data structures/schemas
const typeDefs = require('./server/schema');
@bartcis
bartcis / mock_data_for_gcl.js
Created July 17, 2019 12:47
Mock data for GraphQL excercise
const api = {
books: [
{
title: 'Encyklopedia PWN - A-D',
author: 'Instytut Przyszłości',
},
{
title: 'Encyklopedia PWN - E-G',
author: 'Instytut Przyszłości',
},