Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to relay resolvers #4704

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8c31211
Add context to relay resolvers
Markionium Jun 4, 2024
eefbfbc
start fixing some stuff
Markionium Jul 22, 2024
62a5c7f
Rework resolvercontext based on feedback
Markionium Jul 31, 2024
8f8eb58
fix: flow errors
drewatk Jul 31, 2024
72b6c91
wip: context args typing
drewatk Aug 1, 2024
e0c8311
typegen changes for liveResolverContextType, tests to go
drewatk Aug 7, 2024
1022eba
Update JS tests
drewatk Aug 8, 2024
837ef8c
fix: remove todo comments
drewatk Aug 8, 2024
9e0a159
PR comments
drewatk Aug 9, 2024
3105172
remove branch on live resolvers
drewatk Aug 12, 2024
5b75b96
update JS tests with new resolver args
drewatk Aug 12, 2024
c9eb415
test: fix resolver uts with new arg order
drewatk Aug 12, 2024
5f0a39d
intern macro
drewatk Aug 12, 2024
6f18535
fix: string->stringKey
drewatk Aug 12, 2024
4c2edff
update fixture tests
drewatk Aug 12, 2024
52eff94
Merge remote-tracking branch 'facebook/main' into resolver-context
drewatk Aug 12, 2024
acf8390
fix: weakanimalQueryREsolvers type issue
drewatk Aug 12, 2024
5bb6cc8
nit: unneeded or case
drewatk Aug 13, 2024
6391623
docs update
drewatk Aug 14, 2024
b0fac59
Merge remote-tracking branch 'facebook/main' into resolver-context
drewatk Aug 14, 2024
816b5ea
add link to issue
drewatk Aug 14, 2024
b3d492f
remove "live" from the naming of the context and types
drewatk Aug 14, 2024
520dc93
fix: lint
drewatk Aug 14, 2024
0ab2818
fix: rust lint
drewatk Aug 14, 2024
24e8e6c
add new fixture tests
drewatk Aug 14, 2024
5818987
test: add a JS fixture test for when type is defined it will be ignored
drewatk Aug 14, 2024
78cabf0
Merge remote-tracking branch 'facebook/main' into resolver-context
drewatk Aug 14, 2024
8d8e83a
PR suggestions
drewatk Aug 20, 2024
5963c6f
fix: type errors
drewatk Aug 20, 2024
bf773ec
fix: typegen config doc comments/schema
drewatk Aug 21, 2024
7520e4b
fix: intern
drewatk Aug 21, 2024
1bfd08f
fix: comment
drewatk Aug 21, 2024
5edfef9
fix: schema
drewatk Aug 21, 2024
165ce8f
Merge branch 'main' into resolver-context
drewatk Aug 21, 2024
2913709
Merge branch 'main' into resolver-context
drewatk Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions compiler/crates/relay-compiler/relay-compiler-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,55 @@
"default": false,
"type": "boolean"
},
"resolverContextType": {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you rerun the Rust tests with the flag to update snapshots this should update to include the description

"description": "Indicates the type to import and use as the context for live resolvers.",
"default": null,
"anyOf": [
{
"anyOf": [
{
"description": "Specifies how Relay can import the Resolver context type from a path",
"type": "object",
"required": [
"name",
"path"
],
"properties": {
"name": {
"description": "The name under which the type is exported from the module",
"type": "string"
},
"path": {
"description": "The path to the module relative to the project root",
"type": "string"
}
}
},
{
"description": "Specifies how Relay can import the Resolver context type from a named package",
"type": "object",
"required": [
"name",
"package"
],
"properties": {
"name": {
"description": "The name under which the type is exported from the package",
"type": "string"
},
"package": {
"description": "The name of the package",
"type": "string"
}
}
}
]
},
{
"type": "null"
}
]
},
"resolversSchemaModule": {
"description": "Configuration for resolvers_schema_module generation",
"default": null,
Expand Down Expand Up @@ -4506,6 +4555,55 @@
"default": false,
"type": "boolean"
},
"resolverContextType": {
"description": "Indicates the type to import and use as the context for live resolvers.",
"default": null,
"anyOf": [
{
"anyOf": [
{
"description": "Specifies how Relay can import the Resolver context type from a path",
"type": "object",
"required": [
"name",
"path"
],
"properties": {
"name": {
"description": "The name under which the type is exported from the module",
"type": "string"
},
"path": {
"description": "The path to the module relative to the project root",
"type": "string"
}
}
},
{
"description": "Specifies how Relay can import the Resolver context type from a named package",
"type": "object",
"required": [
"name",
"package"
],
"properties": {
"name": {
"description": "The name under which the type is exported from the package",
"type": "string"
},
"package": {
"description": "The name of the package",
"type": "string"
}
}
}
]
},
{
"type": "null"
}
]
},
"resolversSchemaModule": {
"description": "Configuration for resolvers_schema_module generation",
"default": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Query {
==================================== OUTPUT ===================================
//- __generated__/barMutation.graphql.js
/**
* <auto-generated> SignedSource<<7f1de50339842bab9cecc72c6fbc076f>>
* <auto-generated> SignedSource<<913a56a14897a67a0efd83eeee746bbd>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -47,7 +47,10 @@ import type { ClientRequest, Mutation } from 'relay-runtime';
import {foo_mutation as mutationFooMutationResolverType} from "../foo.js";
// Type assertion validating that `mutationFooMutationResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(mutationFooMutationResolverType: () => ?boolean);
(mutationFooMutationResolverType: (
key: void,
args: void,
) => ?boolean);
export type barMutation$variables = {||};
export type barMutation$data = {|
+foo_mutation: ?boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default node;

//- __generated__/barMutation.graphql.js
/**
* <auto-generated> SignedSource<<6f79ca8d7718498c480388c5b22a5130>>
* <auto-generated> SignedSource<<24fac92f955fdad773281589912aad50>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -121,7 +121,10 @@ import type { ClientRequest, Mutation } from 'relay-runtime';
import {baz_mutation as notCalledMutationBazMutationResolverType} from "../foo.js";
// Type assertion validating that `notCalledMutationBazMutationResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(notCalledMutationBazMutationResolverType: () => ?boolean);
(notCalledMutationBazMutationResolverType: (
key: void,
args: void,
) => ?boolean);
export type barMutation$variables = {||};
export type barMutation$data = {|
+baz_mutation: ?boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface Worker {
==================================== OUTPUT ===================================
//- __generated__/Admin____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<2a569a157aaf5519c1f05d904b6d6d26>>
* <auto-generated> SignedSource<<f1039bde968e467d3d7be1d14a6d78ae>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -76,6 +76,7 @@ import {Admin as adminRelayModelInstanceResolverType} from "Admin";
// A type error here indicates that the type signature of the resolver module is incorrect.
(adminRelayModelInstanceResolverType: (
id: Admin__id$data['id'],
args: void,
) => mixed);
declare export opaque type Admin____relay_model_instance$fragmentType: FragmentType;
export type Admin____relay_model_instance$data = {|
Expand Down Expand Up @@ -175,7 +176,7 @@ module.exports = ((node/*: any*/)/*: Fragment<

//- __generated__/PersonComponentQuery.graphql.js
/**
* <auto-generated> SignedSource<<678979a6fbd285c60deb8d498debb4ca>>
* <auto-generated> SignedSource<<4d89e5370fa457cfc7801675b4bc2515>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -194,13 +195,17 @@ import {admin as adminAdminResolverType} from "Admin";
// A type error here indicates that the type signature of the resolver module is incorrect.
(adminAdminResolverType: (
__relay_model_instance: Admin____relay_model_instance$data['__relay_model_instance'],
args: void,
) => ?{|
+id: DataID,
|});
import {boss as queryBossResolverType} from "Admin";
// Type assertion validating that `queryBossResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(queryBossResolverType: () => ?{|
(queryBossResolverType: (
key: void,
args: void,
) => ?{|
+id: DataID,
|});
export type PersonComponentQuery$variables = {||};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface IPerson {
==================================== OUTPUT ===================================
//- __generated__/Admin____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<43fd74ebd2b94a456ec3c8657edf2868>>
* <auto-generated> SignedSource<<5ee06c79ef9373e880de6ec49a2ad572>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -72,6 +72,7 @@ import {Admin as adminRelayModelInstanceResolverType} from "AdminTypeResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(adminRelayModelInstanceResolverType: (
id: Admin__id$data['id'],
args: void,
) => LiveState<mixed>);
declare export opaque type Admin____relay_model_instance$fragmentType: FragmentType;
export type Admin____relay_model_instance$data = {|
Expand Down Expand Up @@ -261,7 +262,7 @@ module.exports = ((node/*: any*/)/*: Fragment<

//- __generated__/User____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<5b1064cbbcdf6ad4c972e722067e79b2>>
* <auto-generated> SignedSource<<f12a838f373143ebc8da9764d9392147>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -280,6 +281,7 @@ import {User as userRelayModelInstanceResolverType} from "UserTypeResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(userRelayModelInstanceResolverType: (
id: User__id$data['id'],
args: void,
) => LiveState<mixed>);
declare export opaque type User____relay_model_instance$fragmentType: FragmentType;
export type User____relay_model_instance$data = {|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface IActor {
==================================== OUTPUT ===================================
//- __generated__/Admin____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<7fbe3989595c55397f4bcc5c81ec30b2>>
* <auto-generated> SignedSource<<ff27a8e8361738977253b612e9e712e9>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -81,6 +81,7 @@ import {Admin as adminRelayModelInstanceResolverType} from "AdminTypeResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(adminRelayModelInstanceResolverType: (
id: Admin__id$data['id'],
args: void,
) => mixed);
declare export opaque type Admin____relay_model_instance$fragmentType: FragmentType;
export type Admin____relay_model_instance$data = {|
Expand Down Expand Up @@ -180,7 +181,7 @@ module.exports = ((node/*: any*/)/*: Fragment<

//- __generated__/PersonComponentQuery.graphql.js
/**
* <auto-generated> SignedSource<<dbeb4ee17a1c947989956e4d5cdee9eb>>
* <auto-generated> SignedSource<<1dec0e29c12dfaec2fc3769896cd1bb0>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -199,12 +200,16 @@ import {description as iActorDescriptionResolverType} from "IActorResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(iActorDescriptionResolverType: (
model: Admin____relay_model_instance$data['__relay_model_instance'] | User____relay_model_instance$data['__relay_model_instance'],
key: void,
args: void,
) => ?string);
import {name as iPersonNameResolverType} from "IPersonResolvers";
// Type assertion validating that `iPersonNameResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(iPersonNameResolverType: (
model: Admin____relay_model_instance$data['__relay_model_instance'] | User____relay_model_instance$data['__relay_model_instance'],
key: void,
args: void,
) => ?string);
export type PersonComponentQuery$variables = {||};
export type PersonComponentQuery$data = {|
Expand Down Expand Up @@ -489,7 +494,7 @@ module.exports = ((node/*: any*/)/*: ClientQuery<

//- __generated__/User____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<7ffabc2a97c3589cbfd20a23b3b608ca>>
* <auto-generated> SignedSource<<c7e002c5da9941de1b1d513670a0ad1d>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -508,6 +513,7 @@ import {User as userRelayModelInstanceResolverType} from "UserTypeResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(userRelayModelInstanceResolverType: (
id: User__id$data['id'],
args: void,
) => mixed);
declare export opaque type User____relay_model_instance$fragmentType: FragmentType;
export type User____relay_model_instance$data = {|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ interface IActor {
==================================== OUTPUT ===================================
//- __generated__/Admin____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<7fbe3989595c55397f4bcc5c81ec30b2>>
* <auto-generated> SignedSource<<ff27a8e8361738977253b612e9e712e9>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -90,6 +90,7 @@ import {Admin as adminRelayModelInstanceResolverType} from "AdminTypeResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(adminRelayModelInstanceResolverType: (
id: Admin__id$data['id'],
args: void,
) => mixed);
declare export opaque type Admin____relay_model_instance$fragmentType: FragmentType;
export type Admin____relay_model_instance$data = {|
Expand Down Expand Up @@ -484,7 +485,7 @@ module.exports = ((node/*: any*/)/*: ClientQuery<

//- __generated__/User____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<7ffabc2a97c3589cbfd20a23b3b608ca>>
* <auto-generated> SignedSource<<c7e002c5da9941de1b1d513670a0ad1d>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -503,6 +504,7 @@ import {User as userRelayModelInstanceResolverType} from "UserTypeResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(userRelayModelInstanceResolverType: (
id: User__id$data['id'],
args: void,
) => mixed);
declare export opaque type User____relay_model_instance$fragmentType: FragmentType;
export type User____relay_model_instance$data = {|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface IPerson {
==================================== OUTPUT ===================================
//- __generated__/Admin____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<7fbe3989595c55397f4bcc5c81ec30b2>>
* <auto-generated> SignedSource<<ff27a8e8361738977253b612e9e712e9>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -69,6 +69,7 @@ import {Admin as adminRelayModelInstanceResolverType} from "AdminTypeResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(adminRelayModelInstanceResolverType: (
id: Admin__id$data['id'],
args: void,
) => mixed);
declare export opaque type Admin____relay_model_instance$fragmentType: FragmentType;
export type Admin____relay_model_instance$data = {|
Expand Down Expand Up @@ -258,7 +259,7 @@ module.exports = ((node/*: any*/)/*: Fragment<

//- __generated__/User____relay_model_instance.graphql.js
/**
* <auto-generated> SignedSource<<7ffabc2a97c3589cbfd20a23b3b608ca>>
* <auto-generated> SignedSource<<c7e002c5da9941de1b1d513670a0ad1d>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand All @@ -277,6 +278,7 @@ import {User as userRelayModelInstanceResolverType} from "UserTypeResolvers";
// A type error here indicates that the type signature of the resolver module is incorrect.
(userRelayModelInstanceResolverType: (
id: User__id$data['id'],
args: void,
) => mixed);
declare export opaque type User____relay_model_instance$fragmentType: FragmentType;
export type User____relay_model_instance$data = {|
Expand Down
Loading
Loading