Skip to content

Instantly share code, notes, and snippets.

View peggyrayzis's full-sized avatar

Peggy Rayzis peggyrayzis

View GitHub Profile
import { ApolloClient } from 'apollo-client';
import { HttpLink, InMemoryCache, ApolloLink } from 'apollo-boost';
const client = new ApolloClient({
link: ApolloLink.from([ myCustomLink, new HttpLink() ]),
cache: new InMemoryCache()
});
import React from 'react';
import { render } from 'react-dom';
import ApolloClient from 'apollo-boost';
import { ApolloProvider } from 'react-apollo';
// Pass your GraphQL endpoint to uri
const client = new ApolloClient({
uri: 'https://nx9zvp49q7.lp.gql.zone/graphql'
});
@peggyrayzis
peggyrayzis / App.js
Last active February 15, 2018 08:39
Apollo Boost query
import React from 'react';
import { gql } from 'apollo-boost';
import { Query } from 'react-apollo';
const GET_DOG = gql`
query {
dog(breed: "bulldog") {
id
displayImage
}
@peggyrayzis
peggyrayzis / query.js
Last active December 21, 2017 20:53
Example of a client query in apollo-link-state
const GET_USERS_ACTIVE_TODOS = gql`
{
visibilityFilter @client
user(id: 1) {
name
address
}
}
`;
@peggyrayzis
peggyrayzis / mutation.js
Last active December 21, 2017 20:54
Example of a client mutation with apollo-link-state
const SET_VISIBILITY = gql`
mutation SetFilter($filter: String!) {
visibilityFilter(filter: $filter) @client
}
`;
const setVisibilityFilter = graphql(SET_VISIBILITY, {
props: ({ mutate, ownProps }) => ({
onClick: () => mutate({ variables: { filter: ownProps.filter } }),
}),
@peggyrayzis
peggyrayzis / todos.js
Last active August 15, 2019 15:08
Resolvers for apollo-link-state
export const defaults = { // same as before }
export const resolvers = {
Mutation: {
visibilityFilter: (_, { filter }, { cache }) => {
cache.writeData({ data: { visibilityFilter: filter } });
return null;
},
addTodo: (_, { text }, { cache }) => {
const query = gql`
@peggyrayzis
peggyrayzis / todos.js
Last active December 21, 2017 20:19
Defaults for apollo-link-state
export const defaults = {
visibilityFilter: 'SHOW_ALL',
todos: [],
};
@peggyrayzis
peggyrayzis / client.js
Last active December 21, 2017 20:09
Initializing Apollo Client with Apollo Link State
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloLink } from 'apollo-link';
import { withClientState } from 'apollo-link-state';
import { HttpLink } from 'apollo-link-http';
import { defaults, resolvers } from './resolvers/todos';
const cache = new InMemoryCache();
import React, { Component } from 'react';
import { requireNativeComponent } from 'react-native';
const FloatingActionButton = requireNativeComponent(
'FloatingActionButton',
FloatingActionButtonView,
);
export default class FloatingActionButtonView extends Component {
render() {
import React, { Component } from 'react';
import { compose, graphql } from 'react-apollo';
import { NoDataExtension } from '@mls-digital/react-components';
import PostGameExtension from './post-game';
import PreGameExtension from './pre-game';
import PostGameQuery from './post-game.graphql';
import PreGameQuery from './pre-game.graphql';
@compose(
graphql(PreGameQuery, {