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

Federation branch - Modified templates to check for updateMany; added federation prefix from paljs/generator; updated paljs/generator package #26

Open
wants to merge 7 commits into
base: federation
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions apps/api/src/app/graphql/global-schema.gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const typeDefs = gql`
) repeatable on SCHEMA

directive @key(fields: String!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @shareable on FIELD_DEFINITION | OBJECT

extend schema
@link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable"])
Expand Down
22 changes: 11 additions & 11 deletions apps/api/src/app/graphql/paljs/User/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@ import { Resolvers } from '../../resolversTypes';

const resolvers: Resolvers = {
Query: {
findUniqueUser: (_parent, args, { prisma }) => {
Product_findUniqueUser: (_parent, args, { prisma }) => {
return prisma.user.findUnique(args);
},
findFirstUser: (_parent, args, { prisma }) => {
Product_findFirstUser: (_parent, args, { prisma }) => {
return prisma.user.findFirst(args);
},
findManyUser: (_parent, args, { prisma }) => {
Product_findManyUser: (_parent, args, { prisma }) => {
return prisma.user.findMany(args);
},
findManyUserCount: (_parent, args, { prisma }) => {
Product_findManyUserCount: (_parent, args, { prisma }) => {
return prisma.user.count(args);
},
aggregateUser: (_parent, args, { prisma }) => {
Product_aggregateUser: (_parent, args, { prisma }) => {
return prisma.user.aggregate(args);
},
},
Mutation: {
createOneUser: (_parent, args, { prisma }) => {
Product_createOneUser: (_parent, args, { prisma }) => {
return prisma.user.create(args);
},
updateOneUser: (_parent, args, { prisma }) => {
Product_updateOneUser: (_parent, args, { prisma }) => {
return prisma.user.update(args);
},
deleteOneUser: async (_parent, args, { prisma }) => {
Product_deleteOneUser: async (_parent, args, { prisma }) => {
return prisma.user.delete(args);
},
upsertOneUser: async (_parent, args, { prisma }) => {
Product_upsertOneUser: async (_parent, args, { prisma }) => {
return prisma.user.upsert(args);
},
deleteManyUser: async (_parent, args, { prisma }) => {
Product_deleteManyUser: async (_parent, args, { prisma }) => {
return prisma.user.deleteMany(args);
},
updateManyUser: (_parent, args, { prisma }) => {
Product_updateManyUser: (_parent, args, { prisma }) => {
return prisma.user.updateMany(args);
},
},
Expand Down
60 changes: 33 additions & 27 deletions apps/api/src/app/graphql/paljs/User/typeDefs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';

export default gql`
type User @key(fields: "id") {
type User @key(fields: "id") @key(fields: "email") @shareable {
id: Int!
createdAt: DateTime!
username: String
Expand All @@ -13,50 +13,56 @@ export default gql`
}

type Query {
findUniqueUser(where: UserWhereUniqueInput!): User
findFirstUser(
where: UserWhereInput
orderBy: [UserOrderByWithRelationInput]
cursor: UserWhereUniqueInput
Product_findUniqueUser(where: Product_UserWhereUniqueInput!): User
Product_findFirstUser(
where: Product_UserWhereInput
orderBy: [Product_UserOrderByWithRelationInput]
cursor: Product_UserWhereUniqueInput
take: Int
skip: Int
distinct: [UserScalarFieldEnum]
): User
findManyUser(
where: UserWhereInput
orderBy: [UserOrderByWithRelationInput]
cursor: UserWhereUniqueInput
Product_findManyUser(
where: Product_UserWhereInput
orderBy: [Product_UserOrderByWithRelationInput]
cursor: Product_UserWhereUniqueInput
take: Int
skip: Int
distinct: [UserScalarFieldEnum]
): [User!]
findManyUserCount(
where: UserWhereInput
orderBy: [UserOrderByWithRelationInput]
cursor: UserWhereUniqueInput
Product_findManyUserCount(
where: Product_UserWhereInput
orderBy: [Product_UserOrderByWithRelationInput]
cursor: Product_UserWhereUniqueInput
take: Int
skip: Int
distinct: [UserScalarFieldEnum]
): Int!
aggregateUser(
where: UserWhereInput
orderBy: [UserOrderByWithRelationInput]
cursor: UserWhereUniqueInput
Product_aggregateUser(
where: Product_UserWhereInput
orderBy: [Product_UserOrderByWithRelationInput]
cursor: Product_UserWhereUniqueInput
take: Int
skip: Int
): AggregateUser
}

type Mutation {
createOneUser(data: UserCreateInput!): User!
updateOneUser(data: UserUpdateInput!, where: UserWhereUniqueInput!): User!
deleteOneUser(where: UserWhereUniqueInput!): User
upsertOneUser(
where: UserWhereUniqueInput!
create: UserCreateInput!
update: UserUpdateInput!
Product_createOneUser(data: Product_UserCreateInput!): User!
Product_updateOneUser(
data: Product_UserUpdateInput!
where: Product_UserWhereUniqueInput!
): User!
Product_deleteOneUser(where: Product_UserWhereUniqueInput!): User
Product_upsertOneUser(
where: Product_UserWhereUniqueInput!
create: Product_UserCreateInput!
update: Product_UserUpdateInput!
): User
deleteManyUser(where: UserWhereInput): BatchPayload
updateManyUser(data: UserUpdateManyMutationInput!, where: UserWhereInput): BatchPayload
Product_deleteManyUser(where: Product_UserWhereInput): BatchPayload
Product_updateManyUser(
data: Product_UserUpdateManyMutationInput!
where: Product_UserWhereInput
): BatchPayload
}
`;
35 changes: 35 additions & 0 deletions apps/api/src/app/graphql/paljs/model-names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { RenameRootFields, RenameTypes, wrapSchema } from '@graphql-tools/wrap';
import { GraphQLSchema } from 'graphql';

export const modelNames = () => {
return ['User'];
};

//This subgraph's name is set to "Product".
//Input type args is modified to be preceded by "Product_" because inputs are merged using the intersection strategy in the current version of Apollo Federation and directives are not supported with input types.
export const renamedInputTypesSchema = async (schema: GraphQLSchema) => {
const typeMap = schema.getTypeMap();
const models: string = modelNames().join('|');
const inputTypes = Object.keys(typeMap).filter(type => {
const inputTypesRegex = new RegExp(
`(${models})(WhereInput|OrderByWithRelationInput|WhereUniqueInput|OrderByWithAggregationInput|ScalarWhereWithAggregatesInput|CreateInput|UncheckedCreateInput|UpdateInput|UncheckedUpdateInput|CreateManyInput|UpdateManyMutationInput|UncheckedUpdateManyInput|CountOrderByAggregateInput|AvgOrderByAggregateInput|MaxOrderByAggregateInput|MinOrderByAggregateInput|SumOrderByAggregateInput|Create.*?Input|Update.*?Input|Unchecked.*?Input)`
);
return type.match(inputTypesRegex)?.input;
});

return wrapSchema({
schema: schema,
transforms: [
new RenameTypes(name => (inputTypes.includes(name) ? `Product_${name}` : name)),
new RenameRootFields((operation, fieldName) =>
(operation == 'Query' || operation == 'Mutation') &&
fieldName != '_entities' &&
fieldName != '_service' &&
fieldName != 'sampleUpload' &&
fieldName != 'sampleUploadMany'
? `Product_${fieldName}`
: fieldName
),
],
});
};
Loading