-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include Relay resolver import type when field is selected on query as…
… well (#4820) Summary: A [previous PR](#4791) made changes to fix TS import codegen for queries/fragments that select Relay resolver fields. However, when that PR was manually imported, it was only partially applied and missed the necessary change to make codegen work for queries, only the fragments fix was put in place. This PR re-does that change but also adds a test to verify that the code gets generated properly on queries. Previously there were no Relay resolver tests that verified codegen behavior on queries. Relevant issue: #4790 Pull Request resolved: #4820 Reviewed By: tyao1 Differential Revision: D64412751 Pulled By: captbaritone fbshipit-source-id: e63b5429d72cab1c187463f2effc94c23890e14f
- Loading branch information
1 parent
5b7dc1f
commit 682ac5a
Showing
4 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...egen/tests/generate_typescript/fixtures/relay-resolver-on-query-with-output-type.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
==================================== INPUT ==================================== | ||
query Foo_user @raw_response_type { | ||
me { | ||
pop_star_name | ||
} | ||
|
||
} | ||
|
||
fragment PopStarNameResolverFragment_name on User { | ||
name | ||
address { | ||
street | ||
} | ||
parents { | ||
lastName | ||
} | ||
} | ||
|
||
# %extensions% | ||
|
||
extend type User { | ||
pop_star_name: RelayResolverValue @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) | ||
} | ||
==================================== OUTPUT =================================== | ||
import { FragmentRefs } from "relay-runtime"; | ||
import userPopStarNameResolverType from "PopStarNameResolver"; | ||
// Type assertion validating that `userPopStarNameResolverType` resolver is correctly implemented. | ||
// A type error here indicates that the type signature of the resolver module is incorrect. | ||
(userPopStarNameResolverType satisfies ( | ||
rootKey: PopStarNameResolverFragment_name$key, | ||
) => unknown | null | undefined); | ||
export type Foo_user$variables = Record<PropertyKey, never>; | ||
export type Foo_user$data = { | ||
readonly me: { | ||
readonly pop_star_name: ReturnType<typeof userPopStarNameResolverType> | null | undefined; | ||
} | null | undefined; | ||
}; | ||
export type Foo_user$rawResponse = { | ||
readonly me: { | ||
readonly address: { | ||
readonly street: string | null | undefined; | ||
} | null | undefined; | ||
readonly id: string; | ||
readonly name: string | null | undefined; | ||
readonly parents: ReadonlyArray<{ | ||
readonly id: string; | ||
readonly lastName: string | null | undefined; | ||
}>; | ||
} | { | ||
readonly id: string; | ||
} | null | undefined; | ||
}; | ||
export type Foo_user = { | ||
rawResponse: Foo_user$rawResponse; | ||
response: Foo_user$data; | ||
variables: Foo_user$variables; | ||
}; | ||
------------------------------------------------------------------------------- | ||
import { FragmentRefs } from "relay-runtime"; | ||
export type PopStarNameResolverFragment_name$data = { | ||
readonly address: { | ||
readonly street: string | null | undefined; | ||
} | null | undefined; | ||
readonly name: string | null | undefined; | ||
readonly parents: ReadonlyArray<{ | ||
readonly lastName: string | null | undefined; | ||
}>; | ||
readonly " $fragmentType": "PopStarNameResolverFragment_name"; | ||
}; | ||
export type PopStarNameResolverFragment_name$key = { | ||
readonly " $data"?: PopStarNameResolverFragment_name$data; | ||
readonly " $fragmentSpreads": FragmentRefs<"PopStarNameResolverFragment_name">; | ||
}; |
22 changes: 22 additions & 0 deletions
22
...pegen/tests/generate_typescript/fixtures/relay-resolver-on-query-with-output-type.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
query Foo_user @raw_response_type { | ||
me { | ||
pop_star_name | ||
} | ||
|
||
} | ||
|
||
fragment PopStarNameResolverFragment_name on User { | ||
name | ||
address { | ||
street | ||
} | ||
parents { | ||
lastName | ||
} | ||
} | ||
|
||
# %extensions% | ||
|
||
extend type User { | ||
pop_star_name: RelayResolverValue @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters