From 9c9f822b827d5fed9fb0a46bbed2b7433a8a63fd Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 13 Sep 2019 17:28:30 +0200 Subject: [PATCH] [relay-runtime] augment NormalizationSelection (#38351) * augment ReaderSelection * augment NormalizationSelection * test for ConcreteRequest * fix linter issues --- types/relay-runtime/index.d.ts | 8 ++- types/relay-runtime/relay-runtime-tests.tsx | 78 +++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/types/relay-runtime/index.d.ts b/types/relay-runtime/index.d.ts index 51dc9d4f82..87b15b5dc9 100644 --- a/types/relay-runtime/index.d.ts +++ b/types/relay-runtime/index.d.ts @@ -465,6 +465,11 @@ export interface NormalizationDefer { readonly selections: ReadonlyArray; } +export interface NormalizationClientExtension { + kind: string; // 'ClientExtension'; + selections: ReadonlyArray; +} + export type NormalizationField = NormalizationScalarField | NormalizationLinkedField | NormalizationMatchField; export interface NormalizationLinkedField { @@ -509,6 +514,7 @@ export interface NormalizationScalarField { export type NormalizationSelection = | NormalizationCondition + | NormalizationClientExtension | NormalizationField | NormalizationHandle | NormalizationInlineFragment @@ -728,7 +734,7 @@ interface ReaderCondition { } interface ReaderClientExtension { - readonly kind: 'ClientExtension'; + readonly kind: string; // 'ClientExtension'; readonly selections: ReadonlyArray; } diff --git a/types/relay-runtime/relay-runtime-tests.tsx b/types/relay-runtime/relay-runtime-tests.tsx index c1be5435d4..d67ccd164b 100644 --- a/types/relay-runtime/relay-runtime-tests.tsx +++ b/types/relay-runtime/relay-runtime-tests.tsx @@ -1,4 +1,5 @@ import { + ConcreteRequest, Environment, Network, RecordSource, @@ -75,3 +76,80 @@ commitLocalUpdate(environment, store => { const root = store.get(ROOT_ID)!; root.setValue('foo', 'localKey'); }); + +// ~~~~~~~~~~~~~~~~~~~~~ +// ConcreteRequest +// ~~~~~~~~~~~~~~~~~~~~~ + +/* +# client schema +extend type Query { + foo: Boolean! +} +*/ + +/* +// component +graphql` + query FooQuery { + __typename + foo + } +`; +*/ + +/* +query FooQuery { + __typename +} +*/ + +/* tslint:disable:only-arrow-functions no-var-keyword prefer-const */ +const node: ConcreteRequest = (function() { + var v0 = [ + { + kind: 'ScalarField', + alias: null, + name: '__typename', + args: null, + storageKey: null, + }, + { + kind: 'ClientExtension', + selections: [ + { + kind: 'ScalarField', + alias: null, + name: 'foo', + args: null, + storageKey: null, + }, + ], + }, + ]; + return { + kind: 'Request', + fragment: { + kind: 'Fragment', + name: 'FooQuery', + type: 'Query', + metadata: null, + argumentDefinitions: [], + selections: v0 /*: any*/, + }, + operation: { + kind: 'Operation', + name: 'FooQuery', + argumentDefinitions: [], + selections: v0 /*: any*/, + }, + params: { + operationKind: 'query', + name: 'FooQuery', + id: null, + text: 'query FooQuery {\n __typename\n}\n', + metadata: {}, + }, + }; +})(); +/* tslint:enable:only-arrow-functions no-var-keyword prefer-const */