apollo-server 返回模拟数据

模式模拟GraphQL数据

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"
  }
}
posted @ 2018-11-14 23:47  Ajanuw  阅读(215)  评论(0编辑  收藏  举报