From e493bd5ac8875a8c49b658194222bf5312f723dc Mon Sep 17 00:00:00 2001 From: Ola Okelola Date: Mon, 20 Sep 2021 23:10:59 -0700 Subject: [PATCH] update graphql in example --- .../generated/patterns/feedback_query_base.ts | 34 ++--- .../contact_to_comments_connection_type.ts | 18 +++ .../contact_to_likers_connection_type.ts | 18 +++ .../resolvers/generated/contact_type.ts | 77 ++++++++++- .../user/user_to_comments_connection_type.ts | 18 +++ .../user/user_to_likers_connection_type.ts | 18 +++ .../user/user_to_likes_connection_type.ts | 24 ++++ .../user/user_to_post_connection_type.ts | 24 ++++ .../graphql/resolvers/generated/user_type.ts | 124 ++++++++++++++++++ .../simple/src/graphql/resolvers/internal.ts | 6 + examples/simple/src/graphql/schema.gql | 82 +++++++++++- examples/simple/src/graphql/schema.ts | 12 ++ .../src/graphql/tests/contact_type.test.ts | 88 +++++++++++-- .../src/graphql/tests/user_type.test.ts | 52 ++++++++ 14 files changed, 565 insertions(+), 30 deletions(-) create mode 100644 examples/simple/src/graphql/resolvers/generated/contact/contact_to_comments_connection_type.ts create mode 100644 examples/simple/src/graphql/resolvers/generated/contact/contact_to_likers_connection_type.ts create mode 100644 examples/simple/src/graphql/resolvers/generated/user/user_to_comments_connection_type.ts create mode 100644 examples/simple/src/graphql/resolvers/generated/user/user_to_likers_connection_type.ts create mode 100644 examples/simple/src/graphql/resolvers/generated/user/user_to_likes_connection_type.ts create mode 100644 examples/simple/src/graphql/resolvers/generated/user/user_to_post_connection_type.ts diff --git a/examples/simple/src/ent/generated/patterns/feedback_query_base.ts b/examples/simple/src/ent/generated/patterns/feedback_query_base.ts index b7d52e7d1..da1c413c0 100644 --- a/examples/simple/src/ent/generated/patterns/feedback_query_base.ts +++ b/examples/simple/src/ent/generated/patterns/feedback_query_base.ts @@ -30,6 +30,13 @@ import { UserToSelfContactQuery, } from "../../internal"; +export const objectToCommentsCountLoaderFactory = + new AssocEdgeCountLoaderFactory(EdgeType.ObjectToComments); +export const objectToCommentsDataLoaderFactory = new AssocEdgeLoaderFactory( + EdgeType.ObjectToComments, + () => ObjectToCommentsEdge, +); + export const objectToLikersCountLoaderFactory = new AssocEdgeCountLoaderFactory( EdgeType.ObjectToLikers, ); @@ -38,29 +45,22 @@ export const objectToLikersDataLoaderFactory = new AssocEdgeLoaderFactory( () => ObjectToLikersEdge, ); -export const objectToCommentsCountLoaderFactory = - new AssocEdgeCountLoaderFactory(EdgeType.ObjectToComments); -export const objectToCommentsDataLoaderFactory = new AssocEdgeLoaderFactory( - EdgeType.ObjectToComments, - () => ObjectToCommentsEdge, -); - -export class ObjectToLikersQueryBase extends AssocEdgeQueryBase< +export class ObjectToCommentsQueryBase extends AssocEdgeQueryBase< Ent, User, - ObjectToLikersEdge + ObjectToCommentsEdge > { constructor(viewer: Viewer, src: EdgeQuerySource) { super( viewer, src, - objectToLikersCountLoaderFactory, - objectToLikersDataLoaderFactory, + objectToCommentsCountLoaderFactory, + objectToCommentsDataLoaderFactory, User.loaderOptions(), ); } - static query( + static query( this: new (viewer: Viewer, src: EdgeQuerySource) => T, viewer: Viewer, src: EdgeQuerySource, @@ -117,22 +117,22 @@ export class ObjectToLikersQueryBase extends AssocEdgeQueryBase< } } -export class ObjectToCommentsQueryBase extends AssocEdgeQueryBase< +export class ObjectToLikersQueryBase extends AssocEdgeQueryBase< Ent, User, - ObjectToCommentsEdge + ObjectToLikersEdge > { constructor(viewer: Viewer, src: EdgeQuerySource) { super( viewer, src, - objectToCommentsCountLoaderFactory, - objectToCommentsDataLoaderFactory, + objectToLikersCountLoaderFactory, + objectToLikersDataLoaderFactory, User.loaderOptions(), ); } - static query( + static query( this: new (viewer: Viewer, src: EdgeQuerySource) => T, viewer: Viewer, src: EdgeQuerySource, diff --git a/examples/simple/src/graphql/resolvers/generated/contact/contact_to_comments_connection_type.ts b/examples/simple/src/graphql/resolvers/generated/contact/contact_to_comments_connection_type.ts new file mode 100644 index 000000000..83b90e563 --- /dev/null +++ b/examples/simple/src/graphql/resolvers/generated/contact/contact_to_comments_connection_type.ts @@ -0,0 +1,18 @@ +/** + * Copyright whaa whaa + * Generated by github.com/lolopinto/ent/ent, DO NOT EDIT. + */ + +import { GraphQLObjectType } from "graphql"; +import { GraphQLConnectionType } from "@snowtop/ent/graphql"; +import { ContactToCommentsEdge } from "../../../../ent"; +import { UserType } from "../../internal"; + +var connType: GraphQLConnectionType; + +export const ContactToCommentsConnectionType = () => { + if (connType === undefined) { + connType = new GraphQLConnectionType("ContactToCommentsQuery", UserType); + } + return connType; +}; diff --git a/examples/simple/src/graphql/resolvers/generated/contact/contact_to_likers_connection_type.ts b/examples/simple/src/graphql/resolvers/generated/contact/contact_to_likers_connection_type.ts new file mode 100644 index 000000000..905f744b7 --- /dev/null +++ b/examples/simple/src/graphql/resolvers/generated/contact/contact_to_likers_connection_type.ts @@ -0,0 +1,18 @@ +/** + * Copyright whaa whaa + * Generated by github.com/lolopinto/ent/ent, DO NOT EDIT. + */ + +import { GraphQLObjectType } from "graphql"; +import { GraphQLConnectionType } from "@snowtop/ent/graphql"; +import { ContactToLikersEdge } from "../../../../ent"; +import { UserType } from "../../internal"; + +var connType: GraphQLConnectionType; + +export const ContactToLikersConnectionType = () => { + if (connType === undefined) { + connType = new GraphQLConnectionType("ContactToLikersQuery", UserType); + } + return connType; +}; diff --git a/examples/simple/src/graphql/resolvers/generated/contact_type.ts b/examples/simple/src/graphql/resolvers/generated/contact_type.ts index 088b7767a..1d53518b2 100644 --- a/examples/simple/src/graphql/resolvers/generated/contact_type.ts +++ b/examples/simple/src/graphql/resolvers/generated/contact_type.ts @@ -6,14 +6,27 @@ import { GraphQLFieldConfigMap, GraphQLID, + GraphQLInt, GraphQLNonNull, GraphQLObjectType, GraphQLString, } from "graphql"; import { RequestContext } from "@snowtop/ent"; -import { GraphQLNodeInterface, nodeIDEncoder } from "@snowtop/ent/graphql"; -import { Contact } from "../../../ent"; -import { UserType } from "../internal"; +import { + GraphQLEdgeConnection, + GraphQLNodeInterface, + nodeIDEncoder, +} from "@snowtop/ent/graphql"; +import { + Contact, + ContactToCommentsQuery, + ContactToLikersQuery, +} from "../../../ent"; +import { + ContactToCommentsConnectionType, + ContactToLikersConnectionType, + UserType, +} from "../internal"; export const ContactType = new GraphQLObjectType({ name: "Contact", @@ -37,6 +50,64 @@ export const ContactType = new GraphQLObjectType({ lastName: { type: GraphQLNonNull(GraphQLString), }, + comments: { + type: GraphQLNonNull(ContactToCommentsConnectionType()), + args: { + first: { + description: "", + type: GraphQLInt, + }, + after: { + description: "", + type: GraphQLString, + }, + last: { + description: "", + type: GraphQLInt, + }, + before: { + description: "", + type: GraphQLString, + }, + }, + resolve: (contact: Contact, args: {}, context: RequestContext) => { + return new GraphQLEdgeConnection( + contact.viewer, + contact, + (v, contact: Contact) => ContactToCommentsQuery.query(v, contact), + args, + ); + }, + }, + likers: { + type: GraphQLNonNull(ContactToLikersConnectionType()), + args: { + first: { + description: "", + type: GraphQLInt, + }, + after: { + description: "", + type: GraphQLString, + }, + last: { + description: "", + type: GraphQLInt, + }, + before: { + description: "", + type: GraphQLString, + }, + }, + resolve: (contact: Contact, args: {}, context: RequestContext) => { + return new GraphQLEdgeConnection( + contact.viewer, + contact, + (v, contact: Contact) => ContactToLikersQuery.query(v, contact), + args, + ); + }, + }, fullName: { type: GraphQLNonNull(GraphQLString), }, diff --git a/examples/simple/src/graphql/resolvers/generated/user/user_to_comments_connection_type.ts b/examples/simple/src/graphql/resolvers/generated/user/user_to_comments_connection_type.ts new file mode 100644 index 000000000..6edf8f6ce --- /dev/null +++ b/examples/simple/src/graphql/resolvers/generated/user/user_to_comments_connection_type.ts @@ -0,0 +1,18 @@ +/** + * Copyright whaa whaa + * Generated by github.com/lolopinto/ent/ent, DO NOT EDIT. + */ + +import { GraphQLObjectType } from "graphql"; +import { GraphQLConnectionType } from "@snowtop/ent/graphql"; +import { UserToCommentsEdge } from "../../../../ent"; +import { UserType } from "../../internal"; + +var connType: GraphQLConnectionType; + +export const UserToCommentsConnectionType = () => { + if (connType === undefined) { + connType = new GraphQLConnectionType("UserToCommentsQuery", UserType); + } + return connType; +}; diff --git a/examples/simple/src/graphql/resolvers/generated/user/user_to_likers_connection_type.ts b/examples/simple/src/graphql/resolvers/generated/user/user_to_likers_connection_type.ts new file mode 100644 index 000000000..6f239efde --- /dev/null +++ b/examples/simple/src/graphql/resolvers/generated/user/user_to_likers_connection_type.ts @@ -0,0 +1,18 @@ +/** + * Copyright whaa whaa + * Generated by github.com/lolopinto/ent/ent, DO NOT EDIT. + */ + +import { GraphQLObjectType } from "graphql"; +import { GraphQLConnectionType } from "@snowtop/ent/graphql"; +import { UserToLikersEdge } from "../../../../ent"; +import { UserType } from "../../internal"; + +var connType: GraphQLConnectionType; + +export const UserToLikersConnectionType = () => { + if (connType === undefined) { + connType = new GraphQLConnectionType("UserToLikersQuery", UserType); + } + return connType; +}; diff --git a/examples/simple/src/graphql/resolvers/generated/user/user_to_likes_connection_type.ts b/examples/simple/src/graphql/resolvers/generated/user/user_to_likes_connection_type.ts new file mode 100644 index 000000000..acf2aeb04 --- /dev/null +++ b/examples/simple/src/graphql/resolvers/generated/user/user_to_likes_connection_type.ts @@ -0,0 +1,24 @@ +/** + * Copyright whaa whaa + * Generated by github.com/lolopinto/ent/ent, DO NOT EDIT. + */ + +import { GraphQLObjectType } from "graphql"; +import { + GraphQLConnectionType, + GraphQLNodeInterface, +} from "@snowtop/ent/graphql"; +import { UserToLikesEdge } from "../../../../ent"; + +var connType: GraphQLConnectionType; + +export const UserToLikesConnectionType = () => { + if (connType === undefined) { + connType = new GraphQLConnectionType( + "UserToLikes", + + GraphQLNodeInterface, + ); + } + return connType; +}; diff --git a/examples/simple/src/graphql/resolvers/generated/user/user_to_post_connection_type.ts b/examples/simple/src/graphql/resolvers/generated/user/user_to_post_connection_type.ts new file mode 100644 index 000000000..52b19ddc8 --- /dev/null +++ b/examples/simple/src/graphql/resolvers/generated/user/user_to_post_connection_type.ts @@ -0,0 +1,24 @@ +/** + * Copyright whaa whaa + * Generated by github.com/lolopinto/ent/ent, DO NOT EDIT. + */ + +import { GraphQLObjectType } from "graphql"; +import { + GraphQLConnectionType, + GraphQLNodeInterface, +} from "@snowtop/ent/graphql"; +import { UserToPostEdge } from "../../../../ent"; + +var connType: GraphQLConnectionType; + +export const UserToPostConnectionType = () => { + if (connType === undefined) { + connType = new GraphQLConnectionType( + "UserToPost", + + GraphQLNodeInterface, + ); + } + return connType; +}; diff --git a/examples/simple/src/graphql/resolvers/generated/user_type.ts b/examples/simple/src/graphql/resolvers/generated/user_type.ts index 097ebf077..0b36fcd1b 100644 --- a/examples/simple/src/graphql/resolvers/generated/user_type.ts +++ b/examples/simple/src/graphql/resolvers/generated/user_type.ts @@ -20,6 +20,7 @@ import { } from "@snowtop/ent/graphql"; import { User, + UserToCommentsQuery, UserToContactsQuery, UserToCreatedEventsQuery, UserToDeclinedEventsQuery, @@ -27,10 +28,14 @@ import { UserToFriendsQuery, UserToHostedEventsQuery, UserToInvitedEventsQuery, + UserToLikersQuery, + UserToLikesQuery, UserToMaybeEventsQuery, + UserToPostQuery, } from "../../../ent"; import { ContactType, + UserToCommentsConnectionType, UserToContactsConnectionType, UserToCreatedEventsConnectionType, UserToDeclinedEventsConnectionType, @@ -38,7 +43,10 @@ import { UserToFriendsConnectionType, UserToHostedEventsConnectionType, UserToInvitedEventsConnectionType, + UserToLikersConnectionType, + UserToLikesConnectionType, UserToMaybeEventsConnectionType, + UserToPostConnectionType, } from "../internal"; export const UserType = new GraphQLObjectType({ @@ -75,6 +83,35 @@ export const UserType = new GraphQLObjectType({ return user.loadSelfContact(); }, }, + comments: { + type: GraphQLNonNull(UserToCommentsConnectionType()), + args: { + first: { + description: "", + type: GraphQLInt, + }, + after: { + description: "", + type: GraphQLString, + }, + last: { + description: "", + type: GraphQLInt, + }, + before: { + description: "", + type: GraphQLString, + }, + }, + resolve: (user: User, args: {}, context: RequestContext) => { + return new GraphQLEdgeConnection( + user.viewer, + user, + (v, user: User) => UserToCommentsQuery.query(v, user), + args, + ); + }, + }, createdEvents: { type: GraphQLNonNull(UserToCreatedEventsConnectionType()), args: { @@ -220,6 +257,64 @@ export const UserType = new GraphQLObjectType({ ); }, }, + likers: { + type: GraphQLNonNull(UserToLikersConnectionType()), + args: { + first: { + description: "", + type: GraphQLInt, + }, + after: { + description: "", + type: GraphQLString, + }, + last: { + description: "", + type: GraphQLInt, + }, + before: { + description: "", + type: GraphQLString, + }, + }, + resolve: (user: User, args: {}, context: RequestContext) => { + return new GraphQLEdgeConnection( + user.viewer, + user, + (v, user: User) => UserToLikersQuery.query(v, user), + args, + ); + }, + }, + likes: { + type: GraphQLNonNull(UserToLikesConnectionType()), + args: { + first: { + description: "", + type: GraphQLInt, + }, + after: { + description: "", + type: GraphQLString, + }, + last: { + description: "", + type: GraphQLInt, + }, + before: { + description: "", + type: GraphQLString, + }, + }, + resolve: (user: User, args: {}, context: RequestContext) => { + return new GraphQLEdgeConnection( + user.viewer, + user, + (v, user: User) => UserToLikesQuery.query(v, user), + args, + ); + }, + }, maybeEvents: { type: GraphQLNonNull(UserToMaybeEventsConnectionType()), args: { @@ -249,6 +344,35 @@ export const UserType = new GraphQLObjectType({ ); }, }, + post: { + type: GraphQLNonNull(UserToPostConnectionType()), + args: { + first: { + description: "", + type: GraphQLInt, + }, + after: { + description: "", + type: GraphQLString, + }, + last: { + description: "", + type: GraphQLInt, + }, + before: { + description: "", + type: GraphQLString, + }, + }, + resolve: (user: User, args: {}, context: RequestContext) => { + return new GraphQLEdgeConnection( + user.viewer, + user, + (v, user: User) => UserToPostQuery.query(v, user), + args, + ); + }, + }, userToHostedEvents: { type: GraphQLNonNull(UserToHostedEventsConnectionType()), args: { diff --git a/examples/simple/src/graphql/resolvers/internal.ts b/examples/simple/src/graphql/resolvers/internal.ts index 605358e63..1241d9e40 100644 --- a/examples/simple/src/graphql/resolvers/internal.ts +++ b/examples/simple/src/graphql/resolvers/internal.ts @@ -12,11 +12,14 @@ export * from "./generated/event_type"; export * from "./generated/holiday_type"; export * from "./generated/hours_of_operation_type"; export * from "./generated/user_type"; +export * from "./generated/contact/contact_to_comments_connection_type"; +export * from "./generated/contact/contact_to_likers_connection_type"; export * from "./generated/event/event_to_attending_connection_type"; export * from "./generated/event/event_to_declined_connection_type"; export * from "./generated/event/event_to_hosts_connection_type"; export * from "./generated/event/event_to_invited_connection_type"; export * from "./generated/event/event_to_maybe_connection_type"; +export * from "./generated/user/user_to_comments_connection_type"; export * from "./generated/user/user_to_contacts_connection_type"; export * from "./generated/user/user_to_created_events_connection_type"; export * from "./generated/user/user_to_declined_events_connection_type"; @@ -24,5 +27,8 @@ export * from "./generated/user/user_to_events_attending_connection_type"; export * from "./generated/user/user_to_friends_connection_type"; export * from "./generated/user/user_to_hosted_events_connection_type"; export * from "./generated/user/user_to_invited_events_connection_type"; +export * from "./generated/user/user_to_likers_connection_type"; +export * from "./generated/user/user_to_likes_connection_type"; export * from "./generated/user/user_to_maybe_events_connection_type"; +export * from "./generated/user/user_to_post_connection_type"; export * from "./generated/viewer_query_type"; diff --git a/examples/simple/src/graphql/schema.gql b/examples/simple/src/graphql/schema.gql index 7bacb6b1a..6edb34464 100644 --- a/examples/simple/src/graphql/schema.gql +++ b/examples/simple/src/graphql/schema.gql @@ -38,6 +38,8 @@ type Contact implements Node { emailAddress: String! firstName: String! lastName: String! + comments(first: Int, after: String, last: Int, before: String): ContactToCommentsQueryConnection! + likers(first: Int, after: String, last: Int, before: String): ContactToLikersQueryConnection! fullName: String! } @@ -82,12 +84,16 @@ type User implements Node { bio: String nicknames: [String!] selfContact: Contact + comments(first: Int, after: String, last: Int, before: String): UserToCommentsQueryConnection! createdEvents(first: Int, after: String, last: Int, before: String): UserToCreatedEventsConnection! declinedEvents(first: Int, after: String, last: Int, before: String): UserToDeclinedEventsConnection! eventsAttending(first: Int, after: String, last: Int, before: String): UserToEventsAttendingConnection! friends(first: Int, after: String, last: Int, before: String): UserToFriendsConnection! invitedEvents(first: Int, after: String, last: Int, before: String): UserToInvitedEventsConnection! + likers(first: Int, after: String, last: Int, before: String): UserToLikersQueryConnection! + likes(first: Int, after: String, last: Int, before: String): UserToLikesConnection! maybeEvents(first: Int, after: String, last: Int, before: String): UserToMaybeEventsConnection! + post(first: Int, after: String, last: Int, before: String): UserToPostConnection! userToHostedEvents(first: Int, after: String, last: Int, before: String): UserToHostedEventsConnection! contacts(first: Int, after: String, last: Int, before: String): UserToContactsConnection! fullName: String! @@ -99,8 +105,8 @@ type User implements Node { contactsSameDomainNullableContentsAndList: [Contact] } -type EventToAttendingConnection implements Connection { - edges: [EventToAttendingEdge!]! +type ContactToCommentsQueryConnection implements Connection { + edges: [ContactToCommentsQueryEdge!]! nodes: [User!]! pageInfo: PageInfo! rawCount: Int! @@ -126,6 +132,30 @@ type PageInfo { endCursor: String! } +type ContactToCommentsQueryEdge implements Edge { + node: User! + cursor: String! +} + +type ContactToLikersQueryConnection implements Connection { + edges: [ContactToLikersQueryEdge!]! + nodes: [User!]! + pageInfo: PageInfo! + rawCount: Int! +} + +type ContactToLikersQueryEdge implements Edge { + node: User! + cursor: String! +} + +type EventToAttendingConnection implements Connection { + edges: [EventToAttendingEdge!]! + nodes: [User!]! + pageInfo: PageInfo! + rawCount: Int! +} + type EventToAttendingEdge implements Edge { node: User! cursor: String! @@ -179,6 +209,18 @@ type EventToMaybeEdge implements Edge { cursor: String! } +type UserToCommentsQueryConnection implements Connection { + edges: [UserToCommentsQueryEdge!]! + nodes: [User!]! + pageInfo: PageInfo! + rawCount: Int! +} + +type UserToCommentsQueryEdge implements Edge { + node: User! + cursor: String! +} + type UserToContactsConnection implements Connection { edges: [UserToContactsEdge!]! nodes: [Contact!]! @@ -263,6 +305,30 @@ type UserToInvitedEventsEdge implements Edge { cursor: String! } +type UserToLikersQueryConnection implements Connection { + edges: [UserToLikersQueryEdge!]! + nodes: [User!]! + pageInfo: PageInfo! + rawCount: Int! +} + +type UserToLikersQueryEdge implements Edge { + node: User! + cursor: String! +} + +type UserToLikesConnection implements Connection { + edges: [UserToLikesEdge!]! + nodes: [Node!]! + pageInfo: PageInfo! + rawCount: Int! +} + +type UserToLikesEdge implements Edge { + node: Node! + cursor: String! +} + type UserToMaybeEventsConnection implements Connection { edges: [UserToMaybeEventsEdge!]! nodes: [Event!]! @@ -275,6 +341,18 @@ type UserToMaybeEventsEdge implements Edge { cursor: String! } +type UserToPostConnection implements Connection { + edges: [UserToPostEdge!]! + nodes: [Node!]! + pageInfo: PageInfo! + rawCount: Int! +} + +type UserToPostEdge implements Edge { + node: Node! + cursor: String! +} + type Viewer { viewerID: ID user: User diff --git a/examples/simple/src/graphql/schema.ts b/examples/simple/src/graphql/schema.ts index 33ff6e950..95ce6975f 100644 --- a/examples/simple/src/graphql/schema.ts +++ b/examples/simple/src/graphql/schema.ts @@ -92,6 +92,8 @@ import { import { QueryType } from "./resolvers/generated/query_type"; import { AddressType, + ContactToCommentsConnectionType, + ContactToLikersConnectionType, ContactType, EventRsvpStatusType, EventToAttendingConnectionType, @@ -103,6 +105,7 @@ import { GQLViewerType, HolidayType, HoursOfOperationType, + UserToCommentsConnectionType, UserToContactsConnectionType, UserToCreatedEventsConnectionType, UserToDeclinedEventsConnectionType, @@ -110,7 +113,10 @@ import { UserToFriendsConnectionType, UserToHostedEventsConnectionType, UserToInvitedEventsConnectionType, + UserToLikersConnectionType, + UserToLikesConnectionType, UserToMaybeEventsConnectionType, + UserToPostConnectionType, UserType, dayOfWeekType, } from "./resolvers"; @@ -127,11 +133,14 @@ export default new GraphQLSchema({ HolidayType, HoursOfOperationType, UserType, + ContactToCommentsConnectionType(), + ContactToLikersConnectionType(), EventToAttendingConnectionType(), EventToDeclinedConnectionType(), EventToHostsConnectionType(), EventToInvitedConnectionType(), EventToMaybeConnectionType(), + UserToCommentsConnectionType(), UserToContactsConnectionType(), UserToCreatedEventsConnectionType(), UserToDeclinedEventsConnectionType(), @@ -139,7 +148,10 @@ export default new GraphQLSchema({ UserToFriendsConnectionType(), UserToHostedEventsConnectionType(), UserToInvitedEventsConnectionType(), + UserToLikersConnectionType(), + UserToLikesConnectionType(), UserToMaybeEventsConnectionType(), + UserToPostConnectionType(), GQLViewerType, UserAuthInputType, UserAuthJWTInputType, diff --git a/examples/simple/src/graphql/tests/contact_type.test.ts b/examples/simple/src/graphql/tests/contact_type.test.ts index 123e21f64..61f0efb8e 100644 --- a/examples/simple/src/graphql/tests/contact_type.test.ts +++ b/examples/simple/src/graphql/tests/contact_type.test.ts @@ -1,3 +1,4 @@ +import { advanceBy } from "jest-date-mock"; import { DB, LoggedOutViewer, IDViewer, ID, Viewer } from "@snowtop/ent"; import { expectQueryFromRoot, @@ -9,6 +10,8 @@ import schema from "../schema"; import CreateUserAction from "../../ent/user/actions/create_user_action"; import { Contact, User } from "../../ent"; import { randomEmail, randomPhoneNumber } from "../../util/random"; +import EditUserAction from "src/ent/user/actions/edit_user_action"; +import CreateContactAction from "src/ent/contact/actions/create_contact_action"; // TODO we need something that does this by default for all tests afterAll(async () => { @@ -37,21 +40,42 @@ function getConfig( }; } -async function createContact(): Promise { - let user = await CreateUserAction.create(loggedOutViewer, { +function getUserConfig( + viewer: Viewer, + contact: User, + partialConfig?: Partial, +): queryRootConfig { + return { + viewer: viewer, + schema: schema, + root: "node", + args: { + id: encodeGQLID(contact), + }, + inlineFragmentRoot: "User", + ...partialConfig, + }; +} + +async function createUser(): Promise { + return await CreateUserAction.create(loggedOutViewer, { firstName: "Jon", lastName: "Snow", emailAddress: randomEmail(), phoneNumber: randomPhoneNumber(), password: "pa$$w0rd", }).saveX(); - let vc = new IDViewer(user.id); - user = await User.loadX(vc, user.id); - let contact = await user.loadSelfContact(); - if (!contact) { - fail("couldn't load self contact"); +} +async function createContact(user?: User): Promise { + if (!user) { + user = await createUser(); } - return contact; + return await CreateContactAction.create(new IDViewer(user.id), { + emailAddress: randomEmail(), + firstName: "Jon", + lastName: "Snow", + userID: user.id, + }).saveX(); } test("query contact", async () => { @@ -85,3 +109,51 @@ test("query contact with different viewer", async () => { ["id", null], ); }); + +test("likes", async () => { + const user = await createUser(); + const [contact1, contact2, contact3] = await Promise.all([ + createContact(user), + createContact(user), + createContact(user), + ]); + const action = EditUserAction.create(user.viewer, user, {}); + for (const contact of [contact1, contact2, contact3]) { + advanceBy(100); + action.builder.addLike(contact); + } + // for privacy + await action.saveX(); + + await expectQueryFromRoot( + getConfig(new IDViewer(user.id), contact1), + ["likers.rawCount", 1], + [ + "likers.nodes", + [ + { + id: encodeGQLID(user), + }, + ], + ], + ); + + await expectQueryFromRoot( + getUserConfig(new IDViewer(user.id), user), + ["likes.rawCount", 3], + [ + "likes.nodes", + [ + { + id: encodeGQLID(contact1), + }, + { + id: encodeGQLID(contact2), + }, + { + id: encodeGQLID(contact3), + }, + ], + ], + ); +}); diff --git a/examples/simple/src/graphql/tests/user_type.test.ts b/examples/simple/src/graphql/tests/user_type.test.ts index bfb06fc4d..efeba0139 100644 --- a/examples/simple/src/graphql/tests/user_type.test.ts +++ b/examples/simple/src/graphql/tests/user_type.test.ts @@ -582,3 +582,55 @@ test("load fkey connection", async () => { ], ); }); + +test("likes", async () => { + const [user1, user2, user3, user4] = await Promise.all([ + create({}), + create({}), + create({}), + create({}), + ]); + const action = EditUserAction.create(user1.viewer, user1, {}); + for (const user of [user2, user3, user4]) { + advanceBy(100); + action.builder.addLiker(user); + } + // for privacy + action.builder.addFriend(user2, user3, user4); + await action.saveX(); + + await expectQueryFromRoot( + getConfig(new IDViewer(user1.id), user1), + ["likers.rawCount", 3], + [ + "likers.nodes", + [ + { + id: encodeGQLID(user2), + }, + { + id: encodeGQLID(user3), + }, + { + id: encodeGQLID(user4), + }, + ], + ], + ); + + // query likes also + for (const liker of [user2, user3, user4]) { + await expectQueryFromRoot( + getConfig(new IDViewer(liker.id), liker), + ["likes.rawCount", 1], + [ + "likes.nodes", + [ + { + id: encodeGQLID(user1), + }, + ], + ], + ); + } +});