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

Commit bbaf300

Browse files
authored
Merge pull request #139 from ds300/string-literals
Fix opaque types
2 parents 697744c + 2bf3ef7 commit bbaf300

33 files changed

+2049
-3289
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ typings/
6363
/bin
6464

6565
.npmrc
66+
67+
# Build artifacts
68+
.yalc
69+
yalc.lock

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__snapshots__/
2-
fixtures/
2+
fixtures/
3+
example/ts/__relay_artifacts

example/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Relay TodoMVC
22

3+
## Prerequisites
4+
5+
```
6+
yarn global add yalc
7+
```
8+
9+
And in the project root folder
10+
11+
```
12+
yarn watch
13+
```
14+
315
## Installation
416

517
```

example/data/schema.graphql

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,33 @@ type Mutation {
4141
renameTodo(input: RenameTodoInput!): RenameTodoPayload
4242
}
4343

44-
# An object with an ID
44+
"""An object with an ID"""
4545
interface Node {
46-
# The id of the object.
46+
"""The id of the object."""
4747
id: ID!
4848
}
4949

50-
# Information about pagination in a connection.
50+
"""Information about pagination in a connection."""
5151
type PageInfo {
52-
# When paginating forwards, are there more items?
52+
"""When paginating forwards, are there more items?"""
5353
hasNextPage: Boolean!
5454

55-
# When paginating backwards, are there more items?
55+
"""When paginating backwards, are there more items?"""
5656
hasPreviousPage: Boolean!
5757

58-
# When paginating backwards, the cursor to continue.
58+
"""When paginating backwards, the cursor to continue."""
5959
startCursor: String
6060

61-
# When paginating forwards, the cursor to continue.
61+
"""When paginating forwards, the cursor to continue."""
6262
endCursor: String
6363
}
6464

6565
type Query {
6666
viewer: User
6767

68-
# Fetches an object given its ID
68+
"""Fetches an object given its ID"""
6969
node(
70-
# The ID of an object
70+
"""The ID of an object"""
7171
id: ID!
7272
): Node
7373
}
@@ -105,32 +105,32 @@ type RenameTodoPayload {
105105
}
106106

107107
type Todo implements Node {
108-
# The ID of an object
108+
"""The ID of an object"""
109109
id: ID!
110110
text: String
111111
complete: Boolean
112112
}
113113

114-
# A connection to a list of items.
114+
"""A connection to a list of items."""
115115
type TodoConnection {
116-
# Information to aid in pagination.
116+
"""Information to aid in pagination."""
117117
pageInfo: PageInfo!
118118

119-
# A list of edges.
119+
"""A list of edges."""
120120
edges: [TodoEdge]
121121
}
122122

123-
# An edge in a connection.
123+
"""An edge in a connection."""
124124
type TodoEdge {
125-
# The item at the end of the edge
125+
"""The item at the end of the edge"""
126126
node: Todo
127127

128-
# A cursor for use in pagination
128+
"""A cursor for use in pagination"""
129129
cursor: String!
130130
}
131131

132132
type User implements Node {
133-
# The ID of an object
133+
"""The ID of an object"""
134134
id: ID!
135135
todos(status: String = "any", after: String, first: Int, before: String, last: Int): TodoConnection
136136
totalCount: Int

example/package.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"private": true,
33
"scripts": {
44
"start": "babel-node ./server.js",
5-
"build":
6-
"relay-compiler --src ./ts/ --schema ./data/schema.graphql --language typescript --artifactDirectory ./ts/__relay_artifacts__",
5+
"build": "relay-compiler --src ./ts/ --schema ./data/schema.graphql --language typescript --artifactDirectory ./ts/__relay_artifacts__",
76
"update-schema": "babel-node ./scripts/updateSchema.js",
87
"lint": "tslint --project tsconfig.json",
8+
"postinstall": "patch-package",
99
"type-check": "tsc --noEmit --pretty"
1010
},
11-
"resolutions": {
12-
"relay-compiler-language-typescript":
13-
"file:../relay-compiler-language-typescript-v1.1.1-alpha.2.tgz"
11+
"prettier": {
12+
"semi": false,
13+
"trailingComma": "all"
1414
},
1515
"dependencies": {
1616
"@babel/core": "^7.0.0-0",
@@ -25,15 +25,14 @@
2525
"classnames": "2.2.5",
2626
"express": "^4.15.2",
2727
"express-graphql": "^0.7.1",
28-
"graphql": "^14.0.2",
29-
"graphql-compiler": "^2.0.0-rc.1",
30-
"graphql-relay": "^0.5.5",
28+
"graphql": "^14.5.8",
29+
"graphql-compiler": "^1.7.0",
30+
"graphql-relay": "^0.6.0",
3131
"prop-types": "^15.6.2",
32-
"react": "^16.4.1",
33-
"react-dom": "^16.4.1",
34-
"react-relay": "^2.0.0-rc.1",
35-
"relay-devtools": "^1.4.0",
36-
"relay-runtime": "^2.0.0-rc.1",
32+
"react": "^16.10.2",
33+
"react-dom": "^16.10.2",
34+
"react-relay": "^6.0.0",
35+
"relay-runtime": "^6.0.0",
3736
"todomvc-app-css": "^2.1.0",
3837
"todomvc-common": "^1.0.3",
3938
"webpack": "^3.5.5",
@@ -44,18 +43,19 @@
4443
"@types/prop-types": "^15.5.5",
4544
"@types/react": "^16.4.12",
4645
"@types/react-dom": "^16.0.7",
47-
"@types/react-relay": "^1.3.9",
48-
"@types/relay-runtime": "^1.3.5",
46+
"@types/react-relay": "^6.0.1",
47+
"@types/relay-runtime": "^6.0.6",
4948
"babel-cli": "^6.26.0",
5049
"babel-eslint": "6.1.2",
5150
"csstype": "^2.5.6",
5251
"fork-ts-checker-webpack-plugin": "^0.3.0",
53-
"relay-compiler": "^2.0.0-rc.1",
54-
"relay-compiler-language-typescript":
55-
"file:../relay-compiler-language-typescript-v1.1.1-alpha.2.tgz",
56-
"ts-loader": "^3.2.0",
57-
"tslint": "^5.12.0",
52+
"patch-package": "^6.2.0",
53+
"postinstall-postinstall": "^2.0.0",
54+
"relay-compiler": "^6.0.0",
55+
"relay-compiler-language-typescript": "file:.yalc/relay-compiler-language-typescript",
56+
"ts-loader": "^6.2.0",
57+
"tslint": "^5.20.0",
5858
"tslint-plugin-relay": "^0.0.3",
59-
"typescript": "2.9.1"
59+
"typescript": "^3.6.3"
6060
}
6161
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/node_modules/@types/relay-runtime/index.d.ts b/node_modules/@types/relay-runtime/index.d.ts
2+
index 18ff05e..1ab09b6 100644
3+
--- a/node_modules/@types/relay-runtime/index.d.ts
4+
+++ b/node_modules/@types/relay-runtime/index.d.ts
5+
@@ -193,12 +193,20 @@ export { createRelayNetworkLogger } from './lib/network/createRelayNetworkLogger
6+
export { deepFreeze } from './lib/util/deepFreeze';
7+
8+
// These match the output of relay-compiler-language-typescript.
9+
-export interface _RefType<T> {
10+
- ' $refType': T;
11+
+export interface _RefType<T extends string> {
12+
+ " $refType": T;
13+
}
14+
-export interface _FragmentRefs<T> {
15+
- ' $fragmentRefs': T;
16+
+
17+
+export type FragmentRefs<Refs extends string> = {
18+
+ [ref in Refs]: true
19+
+}
20+
+
21+
+export interface _FragmentRefs<Refs extends string> {
22+
+ " $fragmentRefs": FragmentRefs<Refs>
23+
}
24+
25+
// This is a utility type for converting from a data type to a fragment reference that will resolve to that data type.
26+
-export type FragmentRef<T> = T extends _RefType<infer U> ? _FragmentRefs<U> : never;
27+
+export type FragmentRef<T> = T extends _RefType<infer U>
28+
+ ? _FragmentRefs<U>
29+
+ : never;
30+
+

example/ts/__relay_artifacts__/AddTodoMutation.graphql.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ export type AddTodoMutationVariables = {
99
readonly input: AddTodoInput;
1010
};
1111
export type AddTodoMutationResponse = {
12-
readonly addTodo: ({
13-
readonly todoEdge: ({
12+
readonly addTodo: {
13+
readonly todoEdge: {
1414
readonly __typename: string;
1515
readonly cursor: string;
16-
readonly node: ({
16+
readonly node: {
1717
readonly complete: boolean | null;
1818
readonly id: string;
1919
readonly text: string | null;
20-
}) | null;
21-
}) | null;
22-
readonly viewer: ({
20+
} | null;
21+
} | null;
22+
readonly viewer: {
2323
readonly id: string;
2424
readonly totalCount: number | null;
25-
}) | null;
26-
}) | null;
25+
} | null;
26+
} | null;
2727
};
2828
export type AddTodoMutation = {
2929
readonly response: AddTodoMutationResponse;
@@ -80,8 +80,7 @@ v2 = [
8080
{
8181
"kind": "Variable",
8282
"name": "input",
83-
"variableName": "input",
84-
"type": "AddTodoInput!"
83+
"variableName": "input"
8584
}
8685
],
8786
"concreteType": "AddTodoPayload",
@@ -126,7 +125,7 @@ v2 = [
126125
"args": null,
127126
"storageKey": null
128127
},
129-
v1,
128+
(v1/*: any*/),
130129
{
131130
"kind": "ScalarField",
132131
"alias": null,
@@ -147,7 +146,7 @@ v2 = [
147146
"concreteType": "User",
148147
"plural": false,
149148
"selections": [
150-
v1,
149+
(v1/*: any*/),
151150
{
152151
"kind": "ScalarField",
153152
"alias": null,
@@ -162,24 +161,26 @@ v2 = [
162161
];
163162
return {
164163
"kind": "Request",
165-
"operationKind": "mutation",
166-
"name": "AddTodoMutation",
167-
"id": null,
168-
"text": "mutation AddTodoMutation(\n $input: AddTodoInput!\n) {\n addTodo(input: $input) {\n todoEdge {\n __typename\n cursor\n node {\n complete\n id\n text\n }\n }\n viewer {\n id\n totalCount\n }\n }\n}\n",
169-
"metadata": {},
170164
"fragment": {
171165
"kind": "Fragment",
172166
"name": "AddTodoMutation",
173167
"type": "Mutation",
174168
"metadata": null,
175-
"argumentDefinitions": v0,
176-
"selections": v2
169+
"argumentDefinitions": (v0/*: any*/),
170+
"selections": (v2/*: any*/)
177171
},
178172
"operation": {
179173
"kind": "Operation",
180174
"name": "AddTodoMutation",
181-
"argumentDefinitions": v0,
182-
"selections": v2
175+
"argumentDefinitions": (v0/*: any*/),
176+
"selections": (v2/*: any*/)
177+
},
178+
"params": {
179+
"operationKind": "mutation",
180+
"name": "AddTodoMutation",
181+
"id": null,
182+
"text": "mutation AddTodoMutation(\n $input: AddTodoInput!\n) {\n addTodo(input: $input) {\n todoEdge {\n __typename\n cursor\n node {\n complete\n id\n text\n }\n }\n viewer {\n id\n totalCount\n }\n }\n}\n",
183+
"metadata": {}
183184
}
184185
};
185186
})();

example/ts/__relay_artifacts__/ChangeTodoStatusMutation.graphql.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ export type ChangeTodoStatusMutationVariables = {
1010
readonly input: ChangeTodoStatusInput;
1111
};
1212
export type ChangeTodoStatusMutationResponse = {
13-
readonly changeTodoStatus: ({
14-
readonly todo: ({
13+
readonly changeTodoStatus: {
14+
readonly todo: {
1515
readonly id: string;
1616
readonly complete: boolean | null;
17-
}) | null;
18-
readonly viewer: ({
17+
} | null;
18+
readonly viewer: {
1919
readonly id: string;
2020
readonly completedCount: number | null;
21-
}) | null;
22-
}) | null;
21+
} | null;
22+
} | null;
2323
};
2424
export type ChangeTodoStatusMutation = {
2525
readonly response: ChangeTodoStatusMutationResponse;
@@ -71,8 +71,7 @@ v2 = [
7171
{
7272
"kind": "Variable",
7373
"name": "input",
74-
"variableName": "input",
75-
"type": "ChangeTodoStatusInput!"
74+
"variableName": "input"
7675
}
7776
],
7877
"concreteType": "ChangeTodoStatusPayload",
@@ -87,7 +86,7 @@ v2 = [
8786
"concreteType": "Todo",
8887
"plural": false,
8988
"selections": [
90-
v1,
89+
(v1/*: any*/),
9190
{
9291
"kind": "ScalarField",
9392
"alias": null,
@@ -106,7 +105,7 @@ v2 = [
106105
"concreteType": "User",
107106
"plural": false,
108107
"selections": [
109-
v1,
108+
(v1/*: any*/),
110109
{
111110
"kind": "ScalarField",
112111
"alias": null,
@@ -121,24 +120,26 @@ v2 = [
121120
];
122121
return {
123122
"kind": "Request",
124-
"operationKind": "mutation",
125-
"name": "ChangeTodoStatusMutation",
126-
"id": null,
127-
"text": "mutation ChangeTodoStatusMutation(\n $input: ChangeTodoStatusInput!\n) {\n changeTodoStatus(input: $input) {\n todo {\n id\n complete\n }\n viewer {\n id\n completedCount\n }\n }\n}\n",
128-
"metadata": {},
129123
"fragment": {
130124
"kind": "Fragment",
131125
"name": "ChangeTodoStatusMutation",
132126
"type": "Mutation",
133127
"metadata": null,
134-
"argumentDefinitions": v0,
135-
"selections": v2
128+
"argumentDefinitions": (v0/*: any*/),
129+
"selections": (v2/*: any*/)
136130
},
137131
"operation": {
138132
"kind": "Operation",
139133
"name": "ChangeTodoStatusMutation",
140-
"argumentDefinitions": v0,
141-
"selections": v2
134+
"argumentDefinitions": (v0/*: any*/),
135+
"selections": (v2/*: any*/)
136+
},
137+
"params": {
138+
"operationKind": "mutation",
139+
"name": "ChangeTodoStatusMutation",
140+
"id": null,
141+
"text": "mutation ChangeTodoStatusMutation(\n $input: ChangeTodoStatusInput!\n) {\n changeTodoStatus(input: $input) {\n todo {\n id\n complete\n }\n viewer {\n id\n completedCount\n }\n }\n}\n",
142+
"metadata": {}
142143
}
143144
};
144145
})();

0 commit comments

Comments
 (0)