This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of a default GraphQL response | |
const response = { | |
data: { | |
getUser: { | |
__typename: 'User', | |
uid: '5a6efb94b0e8c36f99fba013', | |
email: 'john.doe@yahoo.com', | |
}, | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag' | |
// Apollo Client instance | |
import client from './apollo' | |
const file = new Blob(['Foo.'], { type: 'text/plain' }) | |
// Optional, defaults to `blob` | |
file.name = 'bar.txt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag' | |
import { Mutation } from 'react-apollo' | |
export const UPLOAD_MULTIPLE_FILES = gql` | |
mutation uploadMultipleFiles($files: [Upload!]!) { | |
uploadMultipleFiles(files: $files) { | |
filename | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag' | |
import { Mutation } from 'react-apollo' | |
export const UPLOAD_FILE = gql` | |
mutation uploadFile($file: Upload!) { | |
uploadFile(file: $file) { | |
filename | |
} | |
} | |
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resolvers = { | |
Query: { | |
files: () => { | |
// Return the record of files uploaded from your DB or API or filesystem. | |
} | |
}, | |
Mutation: { | |
async singleUpload(parent, { file }) { | |
const { stream, filename, mimetype, encoding } = await file; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { ApolloServer, gql } = require('apollo-server'); | |
const typeDefs = gql` | |
type File { | |
filename: String! | |
mimetype: String! | |
encoding: String! | |
} | |
type Query { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Dog @cacheControl(maxAge: 120) { | |
id: String! | |
breed: String! | |
displayImage: String @cacheControl(maxAge: 240) | |
images: [Image] | |
subbreeds: [String] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { ApolloServer } = require("apollo-server"); | |
const server = new ApolloSever({ | |
typeDefs, | |
resolvers, | |
engine: { | |
apiKey: "YOUR API KEY HERE" | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { MemcachedCache } = require('apollo-server-memcached'); | |
const { ApolloServe } = require('apollo-server'); | |
const server = new ApolloServer({ | |
... | |
persistedQueries: { | |
cache: new MemcachedCache( | |
['memcached-server-1', 'memcached-server-2', 'memcached-server-3'], | |
{ retries: 10, retry: 10000 }, // Options | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createPersistedQueryLink } from "apollo-link-persisted-queries"; | |
import { createHttpLink } from "apollo-link-http"; | |
import { InMemoryCache } from "apollo-cache-inmemory"; | |
import ApolloClient from "apollo-client"; | |
const link = createPersistedQueryLink().concat(createHttpLink({ uri: "/graphql" })); | |
const client = new ApolloClient({ | |
cache: new InMemoryCache(), | |
link: link, |