apollo-server 返回模拟数据
const { ApolloServer, gql } = require('apollo-server');
const typeDefs = gql`
type Query {
hello: Float
resolved: String
}
`;
const resolvers = {
Query: {
resolved: () => 'Resolved',
},
};
const mocks = {
Int: () => 6,
Float: () => 22.1,
String: () => 'Hello',
};
const server = new ApolloServer({
typeDefs,
resolvers,
mocks,
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
{
hello
resolved
}
{
"data": {
"hello": 22.1,
"resolved": "Hello"
}
}