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

tests: stop using undocumented __resolveObject AS feature #1658

Merged
merged 1 commit into from
Mar 30, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions federation-integration-testsuite-js/src/fixtures/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@ export const url = `https://${name}.api.com.invalid`;
export const typeDefs = gql`
directive @stream on FIELD
directive @transform(from: String!) on FIELD
directive @tag(name: String!) repeatable on
| FIELD_DEFINITION
| INTERFACE
| OBJECT
| UNION
| ARGUMENT_DEFINITION
| SCALAR
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
directive @tag(
name: String!
) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
benweatherman marked this conversation as resolved.
Show resolved Hide resolved

enum CacheControlScope @tag(name: "from-reviews") {
PUBLIC @tag(name: "from-reviews")
Expand All @@ -29,7 +21,9 @@ export const typeDefs = gql`
inheritMaxAge: Boolean
) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION

scalar JSON @tag(name: "from-reviews") @specifiedBy(url: "https://json-spec.dev")
scalar JSON
@tag(name: "from-reviews")
@specifiedBy(url: "https://json-spec.dev")

schema {
query: RootQuery
Expand Down Expand Up @@ -57,11 +51,16 @@ export const typeDefs = gql`
description: String
}

type User @key(fields: "id") @key(fields: "username name { first last }") @tag(name: "from-accounts") {
type User
@key(fields: "id")
@key(fields: "username name { first last }")
@tag(name: "from-accounts") {
id: ID! @tag(name: "accounts")
name: Name @cacheControl(inheritMaxAge: true)
username: String @shareable # Provided by the 'reviews' subgraph
birthDate(locale: String @tag(name: "admin")): String @tag(name: "admin") @tag(name: "dev")
birthDate(locale: String @tag(name: "admin")): String
@tag(name: "admin")
@tag(name: "dev")
account: AccountType
metadata: [UserMetadata]
ssn: String
Expand Down Expand Up @@ -130,21 +129,21 @@ const libraryUsers: { [name: string]: string[] } = {
export const resolvers: GraphQLResolverMap<any> = {
RootQuery: {
user(_, args) {
return { id: args.id };
return users.find((user) => user.id === args.id);
},

me() {
return { id: '1' };
return users.find((user) => user.id === '1');
},
},
User: {
__resolveObject(object) {
__resolveReference(object) {
// Nested key example for @key(fields: "username name { first last }")
if (object.username && object.name.first && object.name.last) {
users.find(user => user.username === object.username);
users.find((user) => user.username === object.username);
}

return users.find(user => user.id === object.id);
return users.find((user) => user.id === object.id);
},
birthDate(user, args) {
return args.locale
Expand All @@ -154,20 +153,20 @@ export const resolvers: GraphQLResolverMap<any> = {
: user.birthDate;
},
metadata(object) {
const metaIndex = metadata.findIndex(m => m.id === object.id);
return metadata[metaIndex].metadata.map(obj => ({ name: obj.name }));
const metaIndex = metadata.findIndex((m) => m.id === object.id);
return metadata[metaIndex].metadata.map((obj) => ({ name: obj.name }));
},
},
UserMetadata: {
address(object) {
const metaIndex = metadata.findIndex(m =>
m.metadata.find(o => o.name === object.name),
const metaIndex = metadata.findIndex((m) =>
m.metadata.find((o) => o.name === object.name),
);
return metadata[metaIndex].metadata[0].address;
},
description(object) {
const metaIndex = metadata.findIndex(m =>
m.metadata.find(o => o.name === object.name),
const metaIndex = metadata.findIndex((m) =>
m.metadata.find((o) => o.name === object.name),
);
return metadata[metaIndex].metadata[0].description;
},
Expand All @@ -177,13 +176,13 @@ export const resolvers: GraphQLResolverMap<any> = {
const libraryUserIds = libraryUsers[name];
return libraryUserIds &&
libraryUserIds.find((id: string) => id === userId)
? { id: userId }
? users.find((user) => user.id === userId)
: null;
},
},
Mutation: {
login(_, args) {
return users.find(user => user.username === args.username);
return users.find((user) => user.username === args.username);
},
},
};
4 changes: 2 additions & 2 deletions federation-integration-testsuite-js/src/fixtures/books.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const books = [

export const resolvers: GraphQLResolverMap<any> = {
Book: {
__resolveObject(object) {
__resolveReference(object) {
return books.find(book => book.isbn === object.isbn);
},
similarBooks(object) {
Expand All @@ -124,7 +124,7 @@ export const resolvers: GraphQLResolverMap<any> = {
},
Query: {
book(_, args) {
return { isbn: args.isbn };
return books.find(book => book.isbn === args.isbn);
},
books() {
return books;
Expand Down
7 changes: 1 addition & 6 deletions gateway-js/src/__tests__/integration/complex-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ const userService: ServiceDefinitionModule = {
);
},
organization(user) {
return { id: user.organizationId };
},
},
Organization: {
__resolveObject(object) {
return organizations.find(org => org.id === object.id);
return organizations.find(org => org.id === user.organizationId);
},
},
},
Expand Down