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

Fix fieldAggregation types #539

Merged
merged 1 commit into from
Oct 18, 2021
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
Empty file.
2 changes: 1 addition & 1 deletion packages/graphql/src/schema/make-augmented-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ function makeAugmentedSchema(
},
});

const baseTypeName = `${node.name}${n.name}${rel.fieldName}`;
const baseTypeName = `${node.name}${n.name}${upperFirst(rel.fieldName)}`;
const fieldAggregationComposer = new FieldAggregationComposer(composer, aggregationSelectionTypes);
const aggregationTypeObject = fieldAggregationComposer.createAggregationTypeObject(
baseTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { ResolveTree } from "graphql-parse-resolve-info";
import { upperFirst } from "graphql-compose";
import { Node, Relationship } from "../../classes";
import { Context, RelationField } from "../../types";
import {
Expand Down Expand Up @@ -58,6 +59,7 @@ export function createFieldAggregation({
const relationAggregationField = node.relationFields.find((x) => {
return `${x.fieldName}Aggregate` === field.name;
});

const connectionField = node.connectionFields.find((x) => {
return `${relationAggregationField?.fieldName}Connection` === x.fieldName;
});
Expand All @@ -68,7 +70,7 @@ export function createFieldAggregation({

if (!referenceNode || !referenceRelation) return undefined;

const fieldPathBase = `${node.name}${referenceNode.name}${relationAggregationField.fieldName}`;
const fieldPathBase = `${node.name}${referenceNode.name}${upperFirst(relationAggregationField.fieldName)}`;
const aggregationFields = getAggregationFields(fieldPathBase, field);

const authData = createFieldAggregationAuth({
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql/tests/schema/aggregations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ describe("Aggregations", () => {

type Post {
likes(options: UserOptions, where: UserWhere): [User]
likesAggregate: PostUserlikesAggregationSelection
likesAggregate: PostUserLikesAggregationSelection
likesConnection(after: String, first: Int, sort: [PostLikesConnectionSort!], where: PostLikesConnectionWhere): PostLikesConnection!
title: String
}
Expand Down Expand Up @@ -1079,13 +1079,13 @@ describe("Aggregations", () => {
title: String
}

type PostUserlikesAggregationSelection {
type PostUserLikesAggregationSelection {
count: Int!
edge: PostUserlikesEdgeAggregateSelection
node: PostUserlikesNodeAggregateSelection
edge: PostUserLikesEdgeAggregateSelection
node: PostUserLikesNodeAggregateSelection
}

type PostUserlikesEdgeAggregateSelection {
type PostUserLikesEdgeAggregateSelection {
someBigInt: BigIntAggregateSelection!
someDateTime: DateTimeAggregateSelection!
someDuration: DurationAggregateSelection!
Expand All @@ -1098,7 +1098,7 @@ describe("Aggregations", () => {
someTime: TimeAggregateSelection!
}

type PostUserlikesNodeAggregateSelection {
type PostUserLikesNodeAggregateSelection {
someBigInt: BigIntAggregateSelection!
someDateTime: DateTimeAggregateSelection!
someDuration: DurationAggregateSelection!
Expand Down
16 changes: 8 additions & 8 deletions packages/graphql/tests/schema/connections/enums.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("Enums", () => {

type Actor {
movies(options: MovieOptions, where: MovieWhere): [Movie]
moviesAggregate: ActorMoviemoviesAggregationSelection
moviesAggregate: ActorMovieMoviesAggregationSelection
moviesConnection(after: String, first: Int, sort: [ActorMoviesConnectionSort!], where: ActorMoviesConnectionWhere): ActorMoviesConnection!
name: String!
}
Expand Down Expand Up @@ -111,12 +111,12 @@ describe("Enums", () => {
movies: [ActorMoviesDisconnectFieldInput!]
}

type ActorMoviemoviesAggregationSelection {
type ActorMovieMoviesAggregationSelection {
count: Int!
node: ActorMoviemoviesNodeAggregateSelection
node: ActorMovieMoviesNodeAggregateSelection
}

type ActorMoviemoviesNodeAggregateSelection {
type ActorMovieMoviesNodeAggregateSelection {
title: StringAggregateSelection!
}

Expand Down Expand Up @@ -287,17 +287,17 @@ describe("Enums", () => {

type Movie {
actors(options: ActorOptions, where: ActorWhere): [Actor]!
actorsAggregate: MovieActoractorsAggregationSelection
actorsAggregate: MovieActorActorsAggregationSelection
actorsConnection(after: String, first: Int, sort: [MovieActorsConnectionSort!], where: MovieActorsConnectionWhere): MovieActorsConnection!
title: String!
}

type MovieActoractorsAggregationSelection {
type MovieActorActorsAggregationSelection {
count: Int!
node: MovieActoractorsNodeAggregateSelection
node: MovieActorActorsNodeAggregateSelection
}

type MovieActoractorsNodeAggregateSelection {
type MovieActorActorsNodeAggregateSelection {
name: StringAggregateSelection!
}

Expand Down
12 changes: 6 additions & 6 deletions packages/graphql/tests/schema/connections/sort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("Sort", () => {
type Node1 {
property: String!
relatedTo(options: Node2Options, where: Node2Where): [Node2!]!
relatedToAggregate: Node1Node2relatedToAggregationSelection
relatedToAggregate: Node1Node2RelatedToAggregationSelection
relatedToConnection(after: String, first: Int, where: Node1RelatedToConnectionWhere): Node1RelatedToConnection!
}

Expand Down Expand Up @@ -107,7 +107,7 @@ describe("Sort", () => {
relatedTo: [Node1RelatedToDisconnectFieldInput!]
}

type Node1Node2relatedToAggregationSelection {
type Node1Node2RelatedToAggregationSelection {
count: Int!
}

Expand Down Expand Up @@ -219,7 +219,7 @@ describe("Sort", () => {

type Node2 {
relatedTo(options: Node1Options, where: Node1Where): [Node1!]!
relatedToAggregate: Node2Node1relatedToAggregationSelection
relatedToAggregate: Node2Node1RelatedToAggregationSelection
relatedToConnection(after: String, first: Int, sort: [Node2RelatedToConnectionSort!], where: Node2RelatedToConnectionWhere): Node2RelatedToConnection!
}

Expand Down Expand Up @@ -247,12 +247,12 @@ describe("Sort", () => {
relatedTo: [Node2RelatedToDisconnectFieldInput!]
}

type Node2Node1relatedToAggregationSelection {
type Node2Node1RelatedToAggregationSelection {
count: Int!
node: Node2Node1relatedToNodeAggregateSelection
node: Node2Node1RelatedToNodeAggregateSelection
}

type Node2Node1relatedToNodeAggregateSelection {
type Node2Node1RelatedToNodeAggregateSelection {
property: StringAggregateSelection!
}

Expand Down
60 changes: 30 additions & 30 deletions packages/graphql/tests/schema/connections/unions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe("Unions", () => {

type Book {
author(options: AuthorOptions, where: AuthorWhere): [Author!]!
authorAggregate: BookAuthorauthorAggregationSelection
authorAggregate: BookAuthorAuthorAggregationSelection
authorConnection(after: String, first: Int, sort: [BookAuthorConnectionSort!], where: BookAuthorConnectionWhere): BookAuthorConnection!
title: String!
}
Expand All @@ -312,6 +312,20 @@ describe("Unions", () => {
node: BookAuthorNodeAggregationWhereInput
}

type BookAuthorAuthorAggregationSelection {
count: Int!
edge: BookAuthorAuthorEdgeAggregateSelection
node: BookAuthorAuthorNodeAggregateSelection
}

type BookAuthorAuthorEdgeAggregateSelection {
words: IntAggregateSelection!
}

type BookAuthorAuthorNodeAggregateSelection {
name: StringAggregateSelection!
}

input BookAuthorConnectFieldInput {
connect: [AuthorConnectInput!]
edge: WroteCreateInput!
Expand Down Expand Up @@ -428,20 +442,6 @@ describe("Unions", () => {
where: BookAuthorConnectionWhere
}

type BookAuthorauthorAggregationSelection {
count: Int!
edge: BookAuthorauthorEdgeAggregateSelection
node: BookAuthorauthorNodeAggregateSelection
}

type BookAuthorauthorEdgeAggregateSelection {
words: IntAggregateSelection!
}

type BookAuthorauthorNodeAggregateSelection {
name: StringAggregateSelection!
}

input BookConnectInput {
author: [BookAuthorConnectFieldInput!]
}
Expand Down Expand Up @@ -539,7 +539,7 @@ describe("Unions", () => {

type Journal {
author(options: AuthorOptions, where: AuthorWhere): [Author!]!
authorAggregate: JournalAuthorauthorAggregationSelection
authorAggregate: JournalAuthorAuthorAggregationSelection
authorConnection(after: String, first: Int, sort: [JournalAuthorConnectionSort!], where: JournalAuthorConnectionWhere): JournalAuthorConnection!
subject: String!
}
Expand All @@ -561,6 +561,20 @@ describe("Unions", () => {
node: JournalAuthorNodeAggregationWhereInput
}

type JournalAuthorAuthorAggregationSelection {
count: Int!
edge: JournalAuthorAuthorEdgeAggregateSelection
node: JournalAuthorAuthorNodeAggregateSelection
}

type JournalAuthorAuthorEdgeAggregateSelection {
words: IntAggregateSelection!
}

type JournalAuthorAuthorNodeAggregateSelection {
name: StringAggregateSelection!
}

input JournalAuthorConnectFieldInput {
connect: [AuthorConnectInput!]
edge: WroteCreateInput!
Expand Down Expand Up @@ -677,20 +691,6 @@ describe("Unions", () => {
where: JournalAuthorConnectionWhere
}

type JournalAuthorauthorAggregationSelection {
count: Int!
edge: JournalAuthorauthorEdgeAggregateSelection
node: JournalAuthorauthorNodeAggregateSelection
}

type JournalAuthorauthorEdgeAggregateSelection {
words: IntAggregateSelection!
}

type JournalAuthorauthorNodeAggregateSelection {
name: StringAggregateSelection!
}

input JournalConnectInput {
author: [JournalAuthorConnectFieldInput!]
}
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql/tests/schema/directives/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("Alias", () => {

type Actor {
actedIn(options: MovieOptions, where: MovieWhere): [Movie]
actedInAggregate: ActorMovieactedInAggregationSelection
actedInAggregate: ActorMovieActedInAggregationSelection
actedInConnection(after: String, first: Int, sort: [ActorActedInConnectionSort!], where: ActorActedInConnectionWhere): ActorActedInConnection!
city: String
name: String!
Expand Down Expand Up @@ -291,18 +291,18 @@ describe("Alias", () => {
actedIn: [ActorActedInDisconnectFieldInput!]
}

type ActorMovieactedInAggregationSelection {
type ActorMovieActedInAggregationSelection {
count: Int!
edge: ActorMovieactedInEdgeAggregateSelection
node: ActorMovieactedInNodeAggregateSelection
edge: ActorMovieActedInEdgeAggregateSelection
node: ActorMovieActedInNodeAggregateSelection
}

type ActorMovieactedInEdgeAggregateSelection {
type ActorMovieActedInEdgeAggregateSelection {
character: StringAggregateSelection!
screenTime: IntAggregateSelection!
}

type ActorMovieactedInNodeAggregateSelection {
type ActorMovieActedInNodeAggregateSelection {
rating: FloatAggregateSelection!
title: StringAggregateSelection!
}
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql/tests/schema/directives/exclude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,17 +614,17 @@ describe("Exclude", () => {

type Movie {
actors(options: ActorOptions, where: ActorWhere): [Actor]
actorsAggregate: MovieActoractorsAggregationSelection
actorsAggregate: MovieActorActorsAggregationSelection
actorsConnection(after: String, first: Int, sort: [MovieActorsConnectionSort!], where: MovieActorsConnectionWhere): MovieActorsConnection!
title: String
}

type MovieActoractorsAggregationSelection {
type MovieActorActorsAggregationSelection {
count: Int!
node: MovieActoractorsNodeAggregateSelection
node: MovieActorActorsNodeAggregateSelection
}

type MovieActoractorsNodeAggregateSelection {
type MovieActorActorsNodeAggregateSelection {
name: StringAggregateSelection!
}

Expand Down
8 changes: 4 additions & 4 deletions packages/graphql/tests/schema/interfaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("Interfaces", () => {
customQuery: [Movie]
id: ID
movies(options: MovieOptions, where: MovieWhere): [Movie]
moviesAggregate: MovieMoviemoviesAggregationSelection
moviesAggregate: MovieMovieMoviesAggregationSelection
moviesConnection(after: String, first: Int, sort: [MovieMoviesConnectionSort!], where: MovieMoviesConnectionWhere): MovieMoviesConnection!
nodes: [MovieNode]
}
Expand Down Expand Up @@ -116,12 +116,12 @@ describe("Interfaces", () => {
movies: [MovieMoviesDisconnectFieldInput!]
}

type MovieMoviemoviesAggregationSelection {
type MovieMovieMoviesAggregationSelection {
count: Int!
node: MovieMoviemoviesNodeAggregateSelection
node: MovieMovieMoviesNodeAggregateSelection
}

type MovieMoviemoviesNodeAggregateSelection {
type MovieMovieMoviesNodeAggregateSelection {
id: IDAggregateSelection!
}

Expand Down
Loading