Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 38927fa

Browse files
thicodesalloy
authored andcommitted
Remove new connection model experiment
1 parent 305f08e commit 38927fa

File tree

5 files changed

+2
-217
lines changed

5 files changed

+2
-217
lines changed

src/TypeScriptGenerator.ts

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
Condition,
3-
createUserError,
43
Fragment,
54
IRVisitor,
65
LinkedField,
@@ -11,15 +10,12 @@ import {
1110
TypeGenerator,
1211
TypeID
1312
} from "relay-compiler";
14-
import { ConnectionField } from "relay-compiler/lib/core/GraphQLIR";
1513
import { TypeGeneratorOptions } from "relay-compiler/lib/language/RelayLanguagePluginInterface";
16-
import * as ConnectionFieldTransform from "relay-compiler/lib/transforms/ConnectionFieldTransform";
1714
import * as FlattenTransform from "relay-compiler/lib/transforms/FlattenTransform";
1815
import * as MaskTransform from "relay-compiler/lib/transforms/MaskTransform";
1916
import * as MatchTransform from "relay-compiler/lib/transforms/MatchTransform";
2017
import * as RefetchableFragmentTransform from "relay-compiler/lib/transforms/RefetchableFragmentTransform";
2118
import * as RelayDirectiveTransform from "relay-compiler/lib/transforms/RelayDirectiveTransform";
22-
import { ConnectionInterface } from "relay-runtime";
2319
import * as ts from "typescript";
2420
import {
2521
State,
@@ -419,7 +415,6 @@ function createVisitor(
419415
existingFragmentNames: options.existingFragmentNames,
420416
generatedFragments: new Set(),
421417
generatedInputObjectTypes: {},
422-
hasConnectionResolver: false,
423418
optionalInputFields: options.optionalInputFields,
424419
usedEnums: {},
425420
usedFragments: new Set(),
@@ -477,9 +472,6 @@ function createVisitor(
477472
state,
478473
node.metadata
479474
);
480-
if (state.hasConnectionResolver) {
481-
state.runtimeImports.add("ConnectionReference");
482-
}
483475
if (refetchableFragmentName !== null) {
484476
state.runtimeImports.add("FragmentReference");
485477
}
@@ -582,9 +574,6 @@ function createVisitor(
582574
])
583575
: baseType;
584576
state.runtimeImports.add("FragmentRefs");
585-
if (state.hasConnectionResolver) {
586-
state.runtimeImports.add("ConnectionReference");
587-
}
588577

589578
return [
590579
importTypes(Array.from(state.runtimeImports).sort(), "relay-runtime"),
@@ -633,10 +622,6 @@ function createVisitor(
633622
ScalarField(node) {
634623
return visitScalarField(schema, node, state);
635624
},
636-
Connection(node) {
637-
return visitConnection(schema, node, state);
638-
},
639-
ConnectionField: visitLinkedField,
640625
LinkedField: visitLinkedField,
641626
ModuleImport(node) {
642627
return [
@@ -669,54 +654,6 @@ function createVisitor(
669654
};
670655
}
671656

672-
function visitConnection(schema: Schema, node: any, state: State) {
673-
const { EDGES } = ConnectionInterface.get();
674-
675-
state.hasConnectionResolver = true;
676-
677-
const edgesSelection = node.selections.find((selections: any) => {
678-
return (
679-
Array.isArray(selections) &&
680-
selections.some(
681-
selection =>
682-
selection != null &&
683-
typeof selection === "object" &&
684-
selection.key === EDGES &&
685-
selection.schemaName === EDGES
686-
)
687-
);
688-
});
689-
690-
const edgesItem = Array.isArray(edgesSelection) ? edgesSelection[0] : null;
691-
692-
const nodeSelections =
693-
edgesItem != null &&
694-
typeof edgesItem === "object" &&
695-
edgesItem.nodeSelections instanceof Map
696-
? edgesItem.nodeSelections
697-
: null;
698-
699-
if (nodeSelections == null) {
700-
throw createUserError(
701-
"Cannot generate flow types for connection field, expected an edges " +
702-
"selection.",
703-
[node.loc]
704-
);
705-
}
706-
707-
const edgesFields = Array.from(nodeSelections.values()) as any[];
708-
709-
const edgesType = selectionsToAST(schema, [edgesFields], state, false);
710-
711-
return [
712-
{
713-
key: "__connection",
714-
conditional: true,
715-
value: ts.createTypeReferenceNode("ConnectionReference", [edgesType])
716-
}
717-
];
718-
}
719-
720657
function visitScalarField(schema: Schema, node: ScalarField, state: State) {
721658
return [
722659
{
@@ -727,7 +664,7 @@ function visitScalarField(schema: Schema, node: ScalarField, state: State) {
727664
];
728665
}
729666

730-
function visitLinkedField(node: LinkedField | ConnectionField) {
667+
function visitLinkedField(node: LinkedField) {
731668
return [
732669
{
733670
key: node.alias || node.name,
@@ -778,8 +715,6 @@ function makeRawResponseProp(
778715
schema,
779716
[Array.from(nullthrows(nodeSelections).values())],
780717
state,
781-
// TODO schema.isWrapper - when update @types/relay-compiler to v8 remove ts-ignore
782-
// @ts-ignore
783718
schema.isAbstractType(nodeType) || schema.isWrapper(nodeType)
784719
? null
785720
: schema.getTypeString(nodeType)
@@ -941,9 +876,6 @@ function createRawResponseTypeVisitor(
941876
ScalarField(node) {
942877
return visitScalarField(schema, node, state);
943878
},
944-
Connection(node) {
945-
return visitConnection(schema, node, state);
946-
},
947879
ClientExtension(node) {
948880
return flattenArray(
949881
/* $FlowFixMe: selections have already been transformed */
@@ -953,7 +885,6 @@ function createRawResponseTypeVisitor(
953885
conditional: true
954886
}));
955887
},
956-
ConnectionField: visitLinkedField,
957888
LinkedField: visitLinkedField,
958889
Condition(node) {
959890
return flattenArray(
@@ -1189,7 +1120,6 @@ function getDataTypeName(name: string): string {
11891120
export const transforms: TypeGenerator["transforms"] = [
11901121
RelayDirectiveTransform.transform,
11911122
MaskTransform.transform,
1192-
ConnectionFieldTransform.transform,
11931123
MatchTransform.transform,
11941124
FlattenTransform.transformWithOptions({}),
11951125
RefetchableFragmentTransform.transform

src/TypeScriptTypeTransformers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export type State = {
1111
generatedInputObjectTypes: {
1212
[name: string]: ts.TypeNode | "pending";
1313
};
14-
hasConnectionResolver: boolean;
1514
matchFields: Map<string, ts.TypeNode>;
1615
runtimeImports: Set<string>;
1716
usedEnums: { [name: string]: TypeID };

test/TypeScriptGenerator-test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-ignore
2-
// TODO - Update CompilerContext type when release @types/relay-compiler 8
31
import { CompilerContext, IRTransforms, Root } from "relay-compiler";
42
import { TypeGeneratorOptions } from "relay-compiler/lib/language/RelayLanguagePluginInterface";
53
import { generateTestsFromFixtures } from "relay-test-utils-internal/lib/generateTestsFromFixtures";
@@ -10,8 +8,7 @@ import * as TypeScriptGenerator from "../src/TypeScriptGenerator";
108
function generate(
119
text,
1210
options: TypeGeneratorOptions,
13-
// TODO - Update CompilerContext type when release @types/relay-compiler 8
14-
context?
11+
context?: CompilerContext
1512
) {
1613
const schema = TestSchema.extend([
1714
...IRTransforms.schemaExtensions,

test/__snapshots__/TypeScriptGenerator-test.ts.snap

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -40,67 +40,6 @@ export type NestedCondition$key = {
4040
4141
`;
4242

43-
exports[`Snapshot tests TypeScriptGenerator with a single artifact directory matches expected output: derived-field.graphql 1`] = `
44-
~~~~~~~~~~ INPUT ~~~~~~~~~~
45-
query QueryWithConnectionField($id: ID!) {
46-
feedback: node(id: $id) {
47-
...FeedbackComments_feedback
48-
}
49-
}
50-
51-
fragment FeedbackComments_feedback on Feedback {
52-
comments(first: 10) @connection_resolver(label: "FeedbackComments_feedback") {
53-
count
54-
edges {
55-
node {
56-
id
57-
}
58-
}
59-
pageInfo {
60-
hasNextPage
61-
}
62-
}
63-
}
64-
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
65-
// QueryWithConnectionField.graphql
66-
import { FragmentRefs } from "relay-runtime";
67-
export type QueryWithConnectionFieldVariables = {
68-
id: string;
69-
};
70-
export type QueryWithConnectionFieldResponse = {
71-
readonly feedback: {
72-
readonly " $fragmentRefs": FragmentRefs<"FeedbackComments_feedback">;
73-
} | null;
74-
};
75-
export type QueryWithConnectionField = {
76-
readonly response: QueryWithConnectionFieldResponse;
77-
readonly variables: QueryWithConnectionFieldVariables;
78-
};
79-
80-
81-
// FeedbackComments_feedback.graphql
82-
import { ConnectionReference, FragmentRefs } from "relay-runtime";
83-
export type FeedbackComments_feedback = {
84-
readonly comments: {
85-
readonly count: number | null;
86-
readonly __connection?: ConnectionReference<{
87-
readonly node: {
88-
readonly id: string;
89-
readonly __id: string;
90-
} | null;
91-
readonly __id: string;
92-
}>;
93-
} | null;
94-
readonly " $refType": "FeedbackComments_feedback";
95-
};
96-
export type FeedbackComments_feedback$data = FeedbackComments_feedback;
97-
export type FeedbackComments_feedback$key = {
98-
readonly " $data"?: FeedbackComments_feedback$data;
99-
readonly " $fragmentRefs": FragmentRefs<"FeedbackComments_feedback">;
100-
};
101-
102-
`;
103-
10443
exports[`Snapshot tests TypeScriptGenerator with a single artifact directory matches expected output: fragment-spread.graphql 1`] = `
10544
~~~~~~~~~~ INPUT ~~~~~~~~~~
10645
fragment FragmentSpread on Node {
@@ -2426,67 +2365,6 @@ export type NestedCondition$key = {
24262365
24272366
`;
24282367
2429-
exports[`Snapshot tests TypeScriptGenerator without a single artifact directory matches expected output: derived-field.graphql 1`] = `
2430-
~~~~~~~~~~ INPUT ~~~~~~~~~~
2431-
query QueryWithConnectionField($id: ID!) {
2432-
feedback: node(id: $id) {
2433-
...FeedbackComments_feedback
2434-
}
2435-
}
2436-
2437-
fragment FeedbackComments_feedback on Feedback {
2438-
comments(first: 10) @connection_resolver(label: "FeedbackComments_feedback") {
2439-
count
2440-
edges {
2441-
node {
2442-
id
2443-
}
2444-
}
2445-
pageInfo {
2446-
hasNextPage
2447-
}
2448-
}
2449-
}
2450-
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
2451-
// QueryWithConnectionField.graphql
2452-
import { FragmentRefs } from "relay-runtime";
2453-
export type QueryWithConnectionFieldVariables = {
2454-
id: string;
2455-
};
2456-
export type QueryWithConnectionFieldResponse = {
2457-
readonly feedback: {
2458-
readonly " $fragmentRefs": FragmentRefs<"FeedbackComments_feedback">;
2459-
} | null;
2460-
};
2461-
export type QueryWithConnectionField = {
2462-
readonly response: QueryWithConnectionFieldResponse;
2463-
readonly variables: QueryWithConnectionFieldVariables;
2464-
};
2465-
2466-
2467-
// FeedbackComments_feedback.graphql
2468-
import { ConnectionReference, FragmentRefs } from "relay-runtime";
2469-
export type FeedbackComments_feedback = {
2470-
readonly comments: {
2471-
readonly count: number | null;
2472-
readonly __connection?: ConnectionReference<{
2473-
readonly node: {
2474-
readonly id: string;
2475-
readonly __id: string;
2476-
} | null;
2477-
readonly __id: string;
2478-
}>;
2479-
} | null;
2480-
readonly " $refType": "FeedbackComments_feedback";
2481-
};
2482-
export type FeedbackComments_feedback$data = FeedbackComments_feedback;
2483-
export type FeedbackComments_feedback$key = {
2484-
readonly " $data"?: FeedbackComments_feedback$data;
2485-
readonly " $fragmentRefs": FragmentRefs<"FeedbackComments_feedback">;
2486-
};
2487-
2488-
`;
2489-
24902368
exports[`Snapshot tests TypeScriptGenerator without a single artifact directory matches expected output: fragment-spread.graphql 1`] = `
24912369
~~~~~~~~~~ INPUT ~~~~~~~~~~
24922370
fragment FragmentSpread on Node {

test/fixtures/type-generator/derived-field.graphql

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)