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

Fix opaque types #139

Merged
merged 11 commits into from Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -63,3 +63,7 @@ typings/
/bin

.npmrc

# Build artifacts
.yalc
yalc.lock
3 changes: 2 additions & 1 deletion .prettierignore
@@ -1,2 +1,3 @@
__snapshots__/
fixtures/
fixtures/
example/ts/__relay_artifacts
12 changes: 12 additions & 0 deletions example/README.md
@@ -1,5 +1,17 @@
# Relay TodoMVC

## Prerequisites

```
yarn global add yalc
```

And in the project root folder

```
yarn watch
```

## Installation

```
Expand Down
34 changes: 17 additions & 17 deletions example/data/schema.graphql
Expand Up @@ -41,33 +41,33 @@ type Mutation {
renameTodo(input: RenameTodoInput!): RenameTodoPayload
}

# An object with an ID
"""An object with an ID"""
interface Node {
# The id of the object.
"""The id of the object."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They ran out of spuds!

id: ID!
}

# Information about pagination in a connection.
"""Information about pagination in a connection."""
type PageInfo {
# When paginating forwards, are there more items?
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!

# When paginating backwards, are there more items?
"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!

# When paginating backwards, the cursor to continue.
"""When paginating backwards, the cursor to continue."""
startCursor: String

# When paginating forwards, the cursor to continue.
"""When paginating forwards, the cursor to continue."""
endCursor: String
}

type Query {
viewer: User

# Fetches an object given its ID
"""Fetches an object given its ID"""
node(
# The ID of an object
"""The ID of an object"""
id: ID!
): Node
}
Expand Down Expand Up @@ -105,32 +105,32 @@ type RenameTodoPayload {
}

type Todo implements Node {
# The ID of an object
"""The ID of an object"""
id: ID!
text: String
complete: Boolean
}

# A connection to a list of items.
"""A connection to a list of items."""
type TodoConnection {
# Information to aid in pagination.
"""Information to aid in pagination."""
pageInfo: PageInfo!

# A list of edges.
"""A list of edges."""
edges: [TodoEdge]
}

# An edge in a connection.
"""An edge in a connection."""
type TodoEdge {
# The item at the end of the edge
"""The item at the end of the edge"""
node: Todo

# A cursor for use in pagination
"""A cursor for use in pagination"""
cursor: String!
}

type User implements Node {
# The ID of an object
"""The ID of an object"""
id: ID!
todos(status: String = "any", after: String, first: Int, before: String, last: Int): TodoConnection
totalCount: Int
Expand Down
42 changes: 21 additions & 21 deletions example/package.json
Expand Up @@ -2,15 +2,15 @@
"private": true,
"scripts": {
"start": "babel-node ./server.js",
"build":
"relay-compiler --src ./ts/ --schema ./data/schema.graphql --language typescript --artifactDirectory ./ts/__relay_artifacts__",
"build": "relay-compiler --src ./ts/ --schema ./data/schema.graphql --language typescript --artifactDirectory ./ts/__relay_artifacts__",
"update-schema": "babel-node ./scripts/updateSchema.js",
"lint": "tslint --project tsconfig.json",
"postinstall": "patch-package",
"type-check": "tsc --noEmit --pretty"
},
"resolutions": {
"relay-compiler-language-typescript":
"file:../relay-compiler-language-typescript-v1.1.1-alpha.2.tgz"
"prettier": {
"semi": false,
"trailingComma": "all"
},
"dependencies": {
"@babel/core": "^7.0.0-0",
Expand All @@ -25,15 +25,14 @@
"classnames": "2.2.5",
"express": "^4.15.2",
"express-graphql": "^0.7.1",
"graphql": "^14.0.2",
"graphql-compiler": "^2.0.0-rc.1",
"graphql-relay": "^0.5.5",
"graphql": "^14.5.8",
"graphql-compiler": "^1.7.0",
"graphql-relay": "^0.6.0",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-relay": "^2.0.0-rc.1",
"relay-devtools": "^1.4.0",
"relay-runtime": "^2.0.0-rc.1",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-relay": "^6.0.0",
"relay-runtime": "^6.0.0",
"todomvc-app-css": "^2.1.0",
"todomvc-common": "^1.0.3",
"webpack": "^3.5.5",
Expand All @@ -44,18 +43,19 @@
"@types/prop-types": "^15.5.5",
"@types/react": "^16.4.12",
"@types/react-dom": "^16.0.7",
"@types/react-relay": "^1.3.9",
"@types/relay-runtime": "^1.3.5",
"@types/react-relay": "^6.0.1",
"@types/relay-runtime": "^6.0.6",
"babel-cli": "^6.26.0",
"babel-eslint": "6.1.2",
"csstype": "^2.5.6",
"fork-ts-checker-webpack-plugin": "^0.3.0",
"relay-compiler": "^2.0.0-rc.1",
"relay-compiler-language-typescript":
"file:../relay-compiler-language-typescript-v1.1.1-alpha.2.tgz",
"ts-loader": "^3.2.0",
"tslint": "^5.12.0",
"patch-package": "^6.2.0",
"postinstall-postinstall": "^2.0.0",
"relay-compiler": "^6.0.0",
"relay-compiler-language-typescript": "file:.yalc/relay-compiler-language-typescript",
"ts-loader": "^6.2.0",
"tslint": "^5.20.0",
"tslint-plugin-relay": "^0.0.3",
"typescript": "2.9.1"
"typescript": "^3.6.3"
}
}
30 changes: 30 additions & 0 deletions example/patches/@types+relay-runtime+6.0.6.patch
@@ -0,0 +1,30 @@
diff --git a/node_modules/@types/relay-runtime/index.d.ts b/node_modules/@types/relay-runtime/index.d.ts
index 18ff05e..1ab09b6 100644
--- a/node_modules/@types/relay-runtime/index.d.ts
+++ b/node_modules/@types/relay-runtime/index.d.ts
@@ -193,12 +193,20 @@ export { createRelayNetworkLogger } from './lib/network/createRelayNetworkLogger
export { deepFreeze } from './lib/util/deepFreeze';

// These match the output of relay-compiler-language-typescript.
-export interface _RefType<T> {
- ' $refType': T;
+export interface _RefType<T extends string> {
+ " $refType": T;
}
-export interface _FragmentRefs<T> {
- ' $fragmentRefs': T;
+
+export type FragmentRefs<Refs extends string> = {
+ [ref in Refs]: true
+}
+
+export interface _FragmentRefs<Refs extends string> {
+ " $fragmentRefs": FragmentRefs<Refs>
}

// This is a utility type for converting from a data type to a fragment reference that will resolve to that data type.
-export type FragmentRef<T> = T extends _RefType<infer U> ? _FragmentRefs<U> : never;
+export type FragmentRef<T> = T extends _RefType<infer U>
+ ? _FragmentRefs<U>
+ : never;
+
43 changes: 22 additions & 21 deletions example/ts/__relay_artifacts__/AddTodoMutation.graphql.ts
Expand Up @@ -9,21 +9,21 @@ export type AddTodoMutationVariables = {
readonly input: AddTodoInput;
};
export type AddTodoMutationResponse = {
readonly addTodo: ({
readonly todoEdge: ({
readonly addTodo: {
readonly todoEdge: {
readonly __typename: string;
readonly cursor: string;
readonly node: ({
readonly node: {
readonly complete: boolean | null;
readonly id: string;
readonly text: string | null;
}) | null;
}) | null;
readonly viewer: ({
} | null;
} | null;
readonly viewer: {
readonly id: string;
readonly totalCount: number | null;
}) | null;
}) | null;
} | null;
} | null;
};
export type AddTodoMutation = {
readonly response: AddTodoMutationResponse;
Expand Down Expand Up @@ -80,8 +80,7 @@ v2 = [
{
"kind": "Variable",
"name": "input",
"variableName": "input",
"type": "AddTodoInput!"
"variableName": "input"
}
],
"concreteType": "AddTodoPayload",
Expand Down Expand Up @@ -126,7 +125,7 @@ v2 = [
"args": null,
"storageKey": null
},
v1,
(v1/*: any*/),
{
"kind": "ScalarField",
"alias": null,
Expand All @@ -147,7 +146,7 @@ v2 = [
"concreteType": "User",
"plural": false,
"selections": [
v1,
(v1/*: any*/),
{
"kind": "ScalarField",
"alias": null,
Expand All @@ -162,24 +161,26 @@ v2 = [
];
return {
"kind": "Request",
"operationKind": "mutation",
"name": "AddTodoMutation",
"id": null,
"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",
"metadata": {},
"fragment": {
"kind": "Fragment",
"name": "AddTodoMutation",
"type": "Mutation",
"metadata": null,
"argumentDefinitions": v0,
"selections": v2
"argumentDefinitions": (v0/*: any*/),
"selections": (v2/*: any*/)
},
"operation": {
"kind": "Operation",
"name": "AddTodoMutation",
"argumentDefinitions": v0,
"selections": v2
"argumentDefinitions": (v0/*: any*/),
"selections": (v2/*: any*/)
},
"params": {
"operationKind": "mutation",
"name": "AddTodoMutation",
"id": null,
"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",
"metadata": {}
}
};
})();
Expand Down
39 changes: 20 additions & 19 deletions example/ts/__relay_artifacts__/ChangeTodoStatusMutation.graphql.ts
Expand Up @@ -10,16 +10,16 @@ export type ChangeTodoStatusMutationVariables = {
readonly input: ChangeTodoStatusInput;
};
export type ChangeTodoStatusMutationResponse = {
readonly changeTodoStatus: ({
readonly todo: ({
readonly changeTodoStatus: {
readonly todo: {
readonly id: string;
readonly complete: boolean | null;
}) | null;
readonly viewer: ({
} | null;
readonly viewer: {
readonly id: string;
readonly completedCount: number | null;
}) | null;
}) | null;
} | null;
} | null;
};
export type ChangeTodoStatusMutation = {
readonly response: ChangeTodoStatusMutationResponse;
Expand Down Expand Up @@ -71,8 +71,7 @@ v2 = [
{
"kind": "Variable",
"name": "input",
"variableName": "input",
"type": "ChangeTodoStatusInput!"
"variableName": "input"
}
],
"concreteType": "ChangeTodoStatusPayload",
Expand All @@ -87,7 +86,7 @@ v2 = [
"concreteType": "Todo",
"plural": false,
"selections": [
v1,
(v1/*: any*/),
{
"kind": "ScalarField",
"alias": null,
Expand All @@ -106,7 +105,7 @@ v2 = [
"concreteType": "User",
"plural": false,
"selections": [
v1,
(v1/*: any*/),
{
"kind": "ScalarField",
"alias": null,
Expand All @@ -121,24 +120,26 @@ v2 = [
];
return {
"kind": "Request",
"operationKind": "mutation",
"name": "ChangeTodoStatusMutation",
"id": null,
"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",
"metadata": {},
"fragment": {
"kind": "Fragment",
"name": "ChangeTodoStatusMutation",
"type": "Mutation",
"metadata": null,
"argumentDefinitions": v0,
"selections": v2
"argumentDefinitions": (v0/*: any*/),
"selections": (v2/*: any*/)
},
"operation": {
"kind": "Operation",
"name": "ChangeTodoStatusMutation",
"argumentDefinitions": v0,
"selections": v2
"argumentDefinitions": (v0/*: any*/),
"selections": (v2/*: any*/)
},
"params": {
"operationKind": "mutation",
"name": "ChangeTodoStatusMutation",
"id": null,
"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",
"metadata": {}
}
};
})();
Expand Down