repo
https://github.com/inspiraller/apollo-typescript
The code runs but Eslint typescript complains though.
I get eslint error on:
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've discovered many alternative libraries to use, ie typegraphql and this seems a good solution for reducing boilerplate typescript types, but it does not provide the answers to what is the strict return type of a query or mutation.
Any help recommended. thanks