Skip to content

Commit

Permalink
feat(graphql,#1058): Allow declaration of custom ID scalar type
Browse files Browse the repository at this point in the history
* Added new IDField decorator to allow specifying a custom ID type to be used for all inputs that require an ID
  • Loading branch information
doug-martin committed May 11, 2021
1 parent 2f5b250 commit fb2ed7a
Show file tree
Hide file tree
Showing 55 changed files with 711 additions and 171 deletions.
1 change: 1 addition & 0 deletions packages/core/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './deep-partial.type';
export * from './class.type';
export * from './reflect.utils';
export * from './class.utils';
export * from './misc.utils';
5 changes: 5 additions & 0 deletions packages/core/src/common/misc.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type NamedType = { name: string };
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
export const isNamed = (SomeType: any): SomeType is NamedType =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
'name' in SomeType && typeof SomeType.name === 'string';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Query {
test(input: DeleteOneCustomId!): Int!
}

input DeleteOneCustomId {
"""The id of the record to delete."""
id: String!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type Query {
test(
"""The id of the record to find."""
id: ID!
): Int!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type Query {
test(
"""The id of the record to find."""
id: String!
): Int!
}
26 changes: 26 additions & 0 deletions packages/query-graphql/__tests__/__fixtures__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,36 @@ export const updateManyResponseTypeSDL = readGraphql(resolve(__dirname, './updat
export const createOneInputTypeSDL = readGraphql(resolve(__dirname, './create-one-input-type.graphql'));
export const createManyInputTypeSDL = readGraphql(resolve(__dirname, './create-many-input-type.graphql'));
export const updateOneInputTypeSDL = readGraphql(resolve(__dirname, './update-one-input-type.graphql'));
export const updateOneCustomIdInputTypeSDL = readGraphql(
resolve(__dirname, './update-one-custom-id-input-type.graphql'),
);
export const updateManyInputTypeSDL = readGraphql(resolve(__dirname, './update-many-input-type.graphql'));
export const deleteOneInputTypeSDL = readGraphql(resolve(__dirname, './delete-one-input-type.graphql'));
export const deleteOneCustomIdInputTypeSDL = readGraphql(
resolve(__dirname, './delete-one-custom-id-input-type.graphql'),
);
export const deleteManyInputTypeSDL = readGraphql(resolve(__dirname, './delete-many-input-type.graphql'));
export const mutationArgsTypeSDL = readGraphql(resolve(__dirname, './mutation-args-type.graphql'));
export const relationInputTypeSDL = readGraphql(resolve(__dirname, './relation-input-type.graphql'));
export const relationCustomParentIdInputTypeSDL = readGraphql(
resolve(__dirname, './relation-custom-parent-id-input-type.graphql'),
);
export const relationCustomRelationIdInputTypeSDL = readGraphql(
resolve(__dirname, './relation-custom-relation-id-input-type.graphql'),
);
export const relationCustomParentRelationIdInputTypeSDL = readGraphql(
resolve(__dirname, './relation-custom-parent-relation-id-input-type.graphql'),
);
export const relationsInputTypeSDL = readGraphql(resolve(__dirname, './relations-input-type.graphql'));
export const relationsCustomParentIdInputTypeSDL = readGraphql(
resolve(__dirname, './relations-custom-parent-id-input-type.graphql'),
);
export const relationsCustomRelationIdInputTypeSDL = readGraphql(
resolve(__dirname, './relations-custom-relation-id-input-type.graphql'),
);
export const relationsCustomParentRelationIdInputTypeSDL = readGraphql(
resolve(__dirname, './relations-custom-parent-relation-id-input-type.graphql'),
);
export const filterInputTypeSDL = readGraphql(resolve(__dirname, './filter-input-type.graphql'));
export const filterAllowedComparisonsInputTypeSDL = readGraphql(
resolve(__dirname, './filter-allowed-comparisons-input-type.graphql'),
Expand All @@ -52,6 +76,8 @@ export const filterAllowedBooleanExpressionsOnlyOrTypeSDL = readGraphql(
export const filterNoBooleanExpressionsTypeSDL = readGraphql(
resolve(__dirname, './filter-no-boolean-expression-type.graphql'),
);
export const findOneArgsTypeSDL = readGraphql(resolve(__dirname, './find-one-args-type.graphql'));
export const findOneCustomIdArgsTypeSDL = readGraphql(resolve(__dirname, './find-one-custom-id-args-type.graphql'));
export const updateFilterInputTypeSDL = readGraphql(resolve(__dirname, './update-filter-input-type.graphql'));
export const deleteFilterInputTypeSDL = readGraphql(resolve(__dirname, './delete-filter-input-type.graphql'));
export const subscriptionFilterInputTypeSDL = readGraphql(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Query {
test(input: RelationCustomParentIdInput!): Int!
}

input RelationCustomParentIdInput {
"""The id of the record."""
id: String!

"""The id of relation."""
relationId: ID!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Query {
test(input: RelationCustomParentAndRelationIdInput!): Int!
}

input RelationCustomParentAndRelationIdInput {
"""The id of the record."""
id: String!

"""The id of relation."""
relationId: String!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Query {
test(input: RelationCustomRelationIdInput!): Int!
}

input RelationCustomRelationIdInput {
"""The id of the record."""
id: ID!

"""The id of relation."""
relationId: String!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Query {
test(input: RelationsCustomParentIdInput!): Int!
}

input RelationsCustomParentIdInput {
"""The id of the record."""
id: String!

"""The ids of the relations."""
relationIds: [ID!]!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Query {
test(input: RelationsCustomParentRelationIdInput!): Int!
}

input RelationsCustomParentRelationIdInput {
"""The id of the record."""
id: String!

"""The ids of the relations."""
relationIds: [String!]!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Query {
test(input: RelationsCustomRelationIdInput!): Int!
}

input RelationsCustomRelationIdInput {
"""The id of the record."""
id: ID!

"""The ids of the relations."""
relationIds: [String!]!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type Query {
updateTest(input: UpdateOneCustomId!): Int!
}

input UpdateOneCustomId {
"""The id of the record to update"""
id: String!

"""The update to apply."""
update: FakeUpdateOneType!
}

input FakeUpdateOneType {
name: String!
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Query {
}

type Mutation {
deleteOneTestResolverDTO(input: DeleteOneInput!): TestResolverDTODeleteResponse!
deleteOneTestResolverDTO(input: DeleteOneTestResolverDTOInput!): TestResolverDTODeleteResponse!
deleteManyTestResolverDTOS(input: DeleteManyTestResolverDTOSInput!): DeleteManyResponse!
}

input DeleteOneInput {
input DeleteOneTestResolverDTOInput {
"""The id of the record to delete."""
id: ID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Query {
}

type Mutation {
deleteOneTestResolverDTO(input: DeleteOneInput!): TestResolverDTODeleteResponse!
deleteOneTestResolverDTO(input: DeleteOneTestResolverDTOInput!): TestResolverDTODeleteResponse!
deleteManyTestResolverDTOS(input: CustomDeleteManyInput!): DeleteManyResponse!
}

input DeleteOneInput {
input DeleteOneTestResolverDTOInput {
"""The id of the record to delete."""
id: ID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Query {
}

type Mutation {
deleteOneTestResolverDTO(input: DeleteOneInput!): TestResolverDTODeleteResponse!
deleteOneTestResolverDTO(input: DeleteOneTestResolverDTOInput!): TestResolverDTODeleteResponse!
delete_many_test(input: DeleteManyTestResolverDTOSInput!): DeleteManyResponse!
}

input DeleteOneInput {
input DeleteOneTestResolverDTOInput {
"""The id of the record to delete."""
id: ID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Query {
}

type Mutation {
deleteOneTest(input: DeleteOneInput!): TestDeleteResponse!
deleteOneTest(input: DeleteOneTestInput!): TestDeleteResponse!
deleteManyTests(input: DeleteManyTestsInput!): DeleteManyResponse!
}

input DeleteOneInput {
input DeleteOneTestInput {
"""The id of the record to delete."""
id: ID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Query {
}

type Mutation {
delete_one_test(input: DeleteOneInput!): TestResolverDTODeleteResponse!
delete_one_test(input: DeleteOneTestResolverDTOInput!): TestResolverDTODeleteResponse!
deleteManyTestResolverDTOS(input: DeleteManyTestResolverDTOSInput!): DeleteManyResponse!
}

input DeleteOneInput {
input DeleteOneTestResolverDTOInput {
"""The id of the record to delete."""
id: ID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ type Query {
}

type Mutation {
deleteOneTestResolverDTO(input: DeleteOneInput!): TestResolverDTODeleteResponse!
deleteOneTestResolverDTO(input: DeleteOneTestResolverDTOInput!): TestResolverDTODeleteResponse!
}

input DeleteOneInput {
input DeleteOneTestResolverDTOInput {
"""The id of the record to delete."""
id: ID!
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Query {
}

type Mutation {
deleteOneTestResolverDTO(input: DeleteOneInput!): TestResolverDTODeleteResponse!
deleteOneTestResolverDTO(input: DeleteOneTestResolverDTOInput!): TestResolverDTODeleteResponse!
deleteManyTestResolverDTOS(input: DeleteManyTestResolverDTOSInput!): DeleteManyResponse!
}

input DeleteOneInput {
input DeleteOneTestResolverDTOInput {
"""The id of the record to delete."""
id: ID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Query {
}

type Mutation {
deleteOneTestResolverDTO(input: DeleteOneInput!): TestResolverDTODeleteResponse!
deleteOneTestResolverDTO(input: DeleteOneTestResolverDTOInput!): TestResolverDTODeleteResponse!
deleteManyTestResolverDTOS(input: DeleteManyTestResolverDTOSInput!): DeleteManyResponse!
}

input DeleteOneInput {
input DeleteOneTestResolverDTOInput {
"""The id of the record to delete."""
id: ID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Query {
}

type Mutation {
deleteOneTestResolverDTO(input: DeleteOneInput!): TestResolverDTODeleteResponse!
deleteOneTestResolverDTO(input: DeleteOneTestResolverDTOInput!): TestResolverDTODeleteResponse!
deleteManyTestResolverDTOS(input: DeleteManyTestResolverDTOSInput!): DeleteManyResponse!
}

input DeleteOneInput {
input DeleteOneTestResolverDTOInput {
"""The id of the record to delete."""
id: ID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ type Query {
}

type Mutation {
removeTestsFromTestResolverDTO(input: RelationsInput!): TestResolverDTO!
removeTestsFromTestResolverDTO(input: RemoveTestsFromTestResolverDTOInput!): TestResolverDTO!
}

input RelationsInput {
input RemoveTestsFromTestResolverDTOInput {
"""The id of the record."""
id: ID!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ type Query {
}

type Mutation {
removeRelationsFromTestResolverDTO(input: RelationsInput!): TestResolverDTO!
removeRelationsFromTestResolverDTO(input: RemoveRelationsFromTestResolverDTOInput!): TestResolverDTO!
}

input RelationsInput {
input RemoveRelationsFromTestResolverDTOInput {
"""The id of the record."""
id: ID!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ type Query {
}

type Mutation {
removeTestFromTestResolverDTO(input: RelationInput!): TestResolverDTO!
removeTestFromTestResolverDTO(input: RemoveTestFromTestResolverDTOInput!): TestResolverDTO!
}

input RelationInput {
input RemoveTestFromTestResolverDTOInput {
"""The id of the record."""
id: ID!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ type Query {
}

type Mutation {
removeRelationFromTestResolverDTO(input: RelationInput!): TestResolverDTO!
removeRelationFromTestResolverDTO(input: RemoveRelationFromTestResolverDTOInput!): TestResolverDTO!
}

input RelationInput {
input RemoveRelationFromTestResolverDTOInput {
"""The id of the record."""
id: ID!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ type Query {
}

type Mutation {
addTestsToTestResolverDTO(input: RelationsInput!): TestResolverDTO!
setTestsOnTestResolverDTO(input: RelationsInput!): TestResolverDTO!
addTestsToTestResolverDTO(input: AddTestsToTestResolverDTOInput!): TestResolverDTO!
setTestsOnTestResolverDTO(input: SetTestsOnTestResolverDTOInput!): TestResolverDTO!
}

input RelationsInput {
input AddTestsToTestResolverDTOInput {
"""The id of the record."""
id: ID!

"""The ids of the relations."""
relationIds: [ID!]!
}

input SetTestsOnTestResolverDTOInput {
"""The id of the record."""
id: ID!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ type Query {
}

type Mutation {
addRelationsToTestResolverDTO(input: RelationsInput!): TestResolverDTO!
setRelationsOnTestResolverDTO(input: RelationsInput!): TestResolverDTO!
addRelationsToTestResolverDTO(input: AddRelationsToTestResolverDTOInput!): TestResolverDTO!
setRelationsOnTestResolverDTO(input: SetRelationsOnTestResolverDTOInput!): TestResolverDTO!
}

input RelationsInput {
input AddRelationsToTestResolverDTOInput {
"""The id of the record."""
id: ID!

"""The ids of the relations."""
relationIds: [ID!]!
}

input SetRelationsOnTestResolverDTOInput {
"""The id of the record."""
id: ID!

Expand Down
Loading

0 comments on commit fb2ed7a

Please sign in to comment.