具有模拟数据的GraphQL无法查询所有结果

时间:2019-04-25 17:53:36

标签: node.js graphql apollo

我是GraphQL的新手,正在寻求帮助。我正在尝试创建六个用户对象,并查询所有六个对象,但是在执行查询时我只会看到两个。谁能帮忙吗?

const { ApolloServer } = require("apollo-server");
const { importSchema } = require("graphql-import");
const { MockList } = require("graphql-tools");
const casual = require("casual");

// Construct a schema, using GraphQL schema language
const typeDefs = importSchema("./schema.graphql");
// Provide resolver functions for your schema fields
const resolvers = {
  Query: {
    hello: () => "Hello world!"
  }
};

const mocks = {
  Query: () => ({
    Member: () => new MockList([0, 6])
  }),
  Member: () => ({
    id: casual.integer(0),
    name: casual.full_name,
    username: casual.username,
    sourceAddress: casual.numerify("+1##########"),
    email: casual.email,
    gender: casual.random_element(["Male", "Female"])
  })
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  mocks
});

server.listen().then(({ url }) => {
  console.log(`Server ready at ${url}`);
});

我输入的查询是

query{
  feed{
    name
  }
}

我得到这些结果

{
  "data": {
    "feed": [
      {
        "name": "Kenyon Reilly"
      },
      {
        "name": "Allan Collier"
      }
    ]
  }
}

任何帮助表示赞赏!

沙箱:

https://codesandbox.io/embed/jz9w42v0py

0 个答案:

没有答案