relay-nextjs
Advanced tools
Comparing version 2.0.0 to 2.0.1
import type { NextPageContext, Redirect } from 'next'; | ||
import { NextRouter } from 'next/router'; | ||
import { ComponentType, ReactNode } from 'react'; | ||
import { PreloadedQuery } from 'react-relay'; | ||
import { PreloadFetchPolicy, PreloadedQuery } from 'react-relay'; | ||
import { Environment, GraphQLResponse, GraphQLTaggedNode, OperationDescriptor, OperationType } from 'relay-runtime'; | ||
@@ -33,2 +33,5 @@ import { HydrationMeta } from './json_meta'; | ||
serverSideProps?: (ctx: NextPageContext) => Promise<OrRedirect<ServerSideProps>>; | ||
fetchPolicy?: PreloadFetchPolicy; | ||
/** Runs after a query has been executed on the server. */ | ||
serverSidePostQuery?: (queryResult: GraphQLResponse | undefined, ctx: NextPageContext) => Promise<unknown> | unknown; | ||
} | ||
@@ -35,0 +38,0 @@ export declare function withRelay<Props extends RelayProps, ServerSideProps extends {}>(Component: ComponentType<Props>, query: GraphQLTaggedNode, opts: RelayOptions<Props, ServerSideProps>): { |
@@ -105,2 +105,3 @@ "use strict"; | ||
function getServerInitialProps(ctx, query, opts) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -129,6 +130,10 @@ const { variablesFromContext = defaultVariablesFromContext } = opts; | ||
const variables = variablesFromContext(ctx); | ||
const preloadedQuery = (0, react_relay_1.loadQuery)(env, query, variables); | ||
const preloadedQuery = (0, react_relay_1.loadQuery)(env, query, variables, { | ||
fetchPolicy: (_a = opts.fetchPolicy) !== null && _a !== void 0 ? _a : 'store-and-network', | ||
}); | ||
const payload = yield ensureQueryFlushed(preloadedQuery); | ||
yield ((_b = opts.serverSidePostQuery) === null || _b === void 0 ? void 0 : _b.call(opts, payload, ctx)); | ||
const payloadSerializationMetadata = (0, json_meta_1.collectMeta)(payload); | ||
const operationDescriptor = (0, relay_runtime_1.createOperationDescriptor)(query.default, variables); | ||
const request = query; | ||
const operationDescriptor = (0, relay_runtime_1.createOperationDescriptor)('default' in request ? request.default : request, variables); | ||
const props = Object.assign(Object.assign({}, serverSideProps), { CSN: false, operationDescriptor, | ||
@@ -135,0 +140,0 @@ payload, payloadMeta: payloadSerializationMetadata }); |
{ | ||
"name": "relay-nextjs", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Use Relay in your Next.js apps!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
28095
404