Skip to content

Instantly share code, notes, and snippets.

Avatar

Giovanni giovannibenussi

View GitHub Profile
View apollo-mocks-app-exchange-rates-new-name-resolver.js
// imports...
import faker from 'faker'
// const typeDefs = ...
const resolvers = {
ExchangeRate: {
name: () => faker.finance.currencyName()
}
}
View apollo-mocks-app-with-mocks.js
import React from 'react'
import ApolloClient from 'apollo-boost'
import { ApolloProvider } from '@apollo/react-hooks'
import Rates from './Rates'
import gql from 'graphql-tag'
const typeDefs = gql`
extend type ExchangeRate {
name: String!
}
View apollo-mocks-app-client-with-mocks.js
const client = new ApolloClient({
uri: 'https://48p1r2roz4.sse.codesandbox.io',
typeDefs,
resolvers
})
View apollo-mocks-app-resolvers.js
const resolvers = {
ExchangeRate: {
name: () => 'This is a custom name!'
}
}
View apollo-mocks-app-type-defs.js
const typeDefs = gql`
extend type ExchangeRate {
name: String!
}
`
View apollo-mocks-app-exchange-rates-name-mapping.js
return data.rates.map(({ name, rate }) => (
<ul key={name}>
<li>
<strong>{name}</strong>: {rate}
</li>
</ul>
))
View apollo-mocks-app-exchange-rates-new-name-field.js
const EXCHANGE_RATES = gql`
{
rates(currency: "USD") {
currency
rate
name @client
}
}
`
View apollo-mocks-app-exchange-rates-import.js
// imports...
import Rates from './Rates'
// client = ...
function App() {
return (
<ApolloProvider client={client}>
...
<Rates />