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 React from 'react'; | |
import { ServerStyleSheet } from 'styled-components'; | |
import { ServerStyleSheets } from '@material-ui/core/styles'; | |
import Document, { Html, Head, Main, NextScript } from 'next/document'; | |
class MyDocument extends Document { | |
static async getInitialProps(context) { | |
const styledComponentsSheet = new ServerStyleSheet(); | |
const materialSheets = new ServerStyleSheets(); | |
const originalRenderPage = context.renderPage; |
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 React from 'react'; | |
import { NextPage } from 'next'; | |
import { DocumentContext } from 'next/document'; | |
import { RelayEnvironmentProvider, fetchQuery } from 'react-relay/hooks'; | |
import { GraphQLTaggedNode, Variables } from 'relay-runtime'; | |
import { initEnvironment } from './createEnvironment'; | |
type OptionsWithData = { | |
query: GraphQLTaggedNode; |
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
export const initEnvironment = (records = {}) => { | |
const network = Network.create(cacheHandler); | |
const source = new RecordSource(records); | |
const store = new Store(source, { | |
// This property tells Relay to not immediately clear its cache when the user | |
// navigates around the app. Relay will hold onto the specified number of | |
// query results, allowing the user to return to recently visited pages | |
// and reusing cached data if its available/fresh. | |
gcReleaseBufferSize: 10, |
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
// Class | |
componentWillReceiveProps(nextProps) { | |
if (nextProps.count !== this.props.count) { | |
console.log('count changed', nextProps.count); | |
} | |
} | |
// Hooks | |
// Skipping first iteration exactly like componentWillReceiveProps: |
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 { subscriptionWithClientId } from 'graphql-relay-subscription'; | |
import UserType from '../UserType'; | |
import * as UserLoader from '../UserLoader'; | |
import pubSub, { EVENTS } from '../../../channels/pubSub'; | |
const UserAddedSubscription = subscriptionWithClientId({ | |
name: 'UserAdded', | |
inputFields: {}, | |
subscribe: () => pubSub.asyncIterator(EVENTS.USER.ADDED), |
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 { graphql, subscribe, parse } from 'graphql'; | |
import { | |
connectMongoose, | |
disconnectMongoose, | |
clearDbAndRestartCounters, | |
getContext, | |
} from '../../../../../test/helpers'; | |
import { schema } from '../../../../schema/schema'; |
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 mutation = createEditSingleFieldMutation({ | |
name: 'UserEditName', | |
model: User, | |
fieldName: 'title', | |
fieldType: GraphQLString, | |
clearCache: UserLoader.clearCache, | |
notFoundMessage: ({ t }) => t('User not found'), | |
successMessage: ({ t }) => t('User edited successfully'), | |
outputFields: { | |
user: { |
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 { toGlobalId } from 'graphql-relay'; | |
import { Types } from 'mongoose'; | |
import { getObjectId } from './getObjectId'; | |
import { | |
clearDbAndRestartCounters, | |
connectMongoose, | |
createUser, | |
disconnectMongoose | |
} from '../../../test/helpers'; |
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
export type DataLoaderKey = string | Types.ObjectId | Object; | |
export type Load = (context: GraphQLContext, id: DataLoaderKey) => any; | |
type TypeLoaders = { | |
[key: string]: { | |
type: GraphQLObjectType, | |
load: Load, | |
}; | |
}; |
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
export type GetLoader = () => DataLoader<string, any>; | |
type Dataloaders = { | |
[loader: string]: GetLoader; | |
}; | |
const dataloaders: Dataloaders = {}; | |
export const registerDataLoader = (name: string, getLoader: GetLoader) => { | |
dataloaders[name] = getLoader; | |
}; |