Hello i have a question related to apollo federation, ive been using apollo server to experiment with graphql and typescript i had everything working but i wanted to move to apollo federation, i had to change the schema building method to buildSubgraphSchema and i am having some troubles with the type definitions of my resolvers.
this is my graphql schema:
import { gql } from 'apollo-server-koa';
const typeDefs = gql`
type State {
stateId: Int
name: String
}
extend type Query {
state(stateId: Int!): State
stateList: [State]
}
extend type Mutation {
createState(
name: String!
) : State
updateState(
stateId: Int!
name: String!
) : State
deleteState(
stateId: Int!
) : State
}
`;
export default typeDefs;
this was my resolver in apollo server:
import { PrismaClient } from '@prisma/client';
import { State, UpdateStateInput, DeleteStateInput } from '../types/state';
const prisma = new PrismaClient();
const stateResolver = {
Query: {
state: (_params: any, args: { stateId: number }) => {
return prisma.state.findUnique({
where: { stateId: args.stateId || undefined },
});
},
stateList: () => {
return prisma.state.findMany();
},
},
Mutation: {
createState: (_parent: any, args: State) => {
return prisma.state.create({ data: { name: args.name } });
},
updateState: (_parent: any, args: UpdateStateInput) => {
const { stateId, ...data } = args;
return prisma.state.update({ where: { stateId }, data });
},
deleteState: (_parent: any, args: DeleteStateInput) => {
return prisma.state.delete({ where: { stateId: args.stateId } });
},
},
// Relation resolvers
State: {
notary: (parent: any) => {
return prisma.notary.findMany({ where: { stateId: parent?.stateId } });
},
},
};
export default stateResolver;
When i pass that resolver to buildSubgraphSchema, typescript shows this error:
Type '{ Query: { state: (_params: any, args: { stateId: number;}) => Prisma.Prisma__StateClient<State | null>; stateList: () => PrismaPromise<State[]>; }; Mutation: { createState: (_parent: any, args: State) => Prisma.Prisma__StateClient<...>; updateState: (_parent: any, args: UpdateStateInput) => Prisma.Prisma__StateC...' is not assignable to type 'GraphQLResolverMap<any>'.
Property 'Query' is incompatible with index signature.
Type '{ state: (_params: any, args: { stateId: number;}) => Prisma.Prisma__StateClient<State | null>; stateList: () => PrismaPromise<State[]>; }' is not assignable to type 'GraphQLScalarType | { [enumValue: string]: string | number; } | { [fieldName: string]: GraphQLFieldResolver<any, any, { [argName: string]: any; }> | { ...; }; }'.
Type '{ state: (_params: any, args: { stateId: number;}) => Prisma.Prisma__StateClient<State | null>; stateList: () => PrismaPromise<State[]>; }' is not assignable to type '{ [fieldName: string]: GraphQLFieldResolver<any, any, { [argName: string]: any; }> | { requires?: string | undefined; resolve: GraphQLFieldResolver<any, any, { [argName: string]: any; }>; }; }'.
Property 'state' is incompatible with index signature.
Type '(_params: any, args: { stateId: number;}) => Prisma.Prisma__StateClient<State | null>' is not assignable to type 'GraphQLFieldResolver<any, any, { [argName: string]: any; }> | { requires?: string | undefined; resolve: GraphQLFieldResolver<any, any, { [argName: string]: any; }>; }'.
Type '(_params: any, args: { stateId: number;}) => Prisma.Prisma__StateClient<State | null>' is not assignable to type 'GraphQLFieldResolver<any, any, { [argName: string]: any; }>'.
Types of parameters 'args' and 'args' are incompatible.
Property 'stateId' is missing in type '{ [argName: string]: any; }' but required in type '{ stateId: number; }'.
the error gets solved if i set args: any on all the resolver methods. i wanted to know if that is the correct way considering that it loses the type definitions there.
thanks.