Repository Link
https://github.com/inspiraller/apollo-typescript
The code is functioning correctly, however, Eslint typescript is raising complaints.
An eslint error occurs on the following code block:
Query: {
players: () => players
}
Missing return type on function.eslint@typescript-eslint/explicit-module-boundary-types
index.ts
import { ApolloServer } from 'apollo-server';
import typeDefs from './schema';
import resolvers from './resolvers';
const init = () => {
const server: ApolloServer = new ApolloServer({
typeDefs,
resolvers
});
server.listen().then((props: { url: string }) => {
const { url } = props;
console.log(`Server ready at ${url}`);
});
};
init();
schema.ts
import { gql } from 'apollo-server';
const typeDefs = gql`
type Player {
id: String
name: String
}
type Query {
players: [Player]!
}
input PlayerInput {
name: String
}
type Mutation {
addPlayer(player: PlayerInput!): Player
}
`;
export default typeDefs;
resolvers.ts
interface shapePlayer {
id: string;
name: string;
}
const players: Array<shapePlayer> = [
{
id: 'alpha',
name: 'terry'
},
{
id: 'beta',
name: 'pc'
}
];
interface shapeResolver {
Query: {
players: () => Array<shapePlayer> | null | undefined | void;
};
}
const resolvers: shapeResolver = {
Query: {
players: () => players
}
};
export default resolvers;
I have explored various alternative libraries like TypeGraphQL, which appears to be a promising solution for reducing TypeScript boilerplate. However, it does not address the issue of determining the strict return type of a query or mutation.
If anyone has any recommendations or assistance, please feel free to share. Thank you!