在GraphQL上查询Relay Modern interogation时的空响应

时间:2017-10-03 13:56:55

标签: mongodb graphql graphql-js relaymodern

也许设法通过这一步的人愿意提供一些指示。

我有一个架构,一个解析器,我请求查询,我有一个空响应。 请问关于主题的帮助吗?

module.exports = {
  Query: {
    allLinks: async (root, {filter}, {mongo: {Links, Users}}) => {
      let query = filter ? {$or: buildFilters(filter)} : {};
      return await Links.find(query).toArray();
    }

,查询请求如下所示:

    query LinkListPageQuery {
  allLinks {
    ...LinkList_allLinks
  }
}

fragment LinkList_allLinks on LinkConnection {
  edges {
    cursor
    ...Link_link
  }
}

fragment Link_link on LinkEdge {
  node {
    id
    description 
    url
  }
}

我的架构如下所示:

const typeDefs = `
    type Link implements Node {
      id: ID!
      url: String!
      description: String!
      postedBy: User
      votes: [Vote!]!
    }
    interface Node {
      id: ID!
    }
    type Query {
      allLinks(filter: LinkFilter, first: Int): [LinkConnection]
      node(
        id: ID!
        ): Node
    }
    type LinkEdge {
      node: Link!
      cursor: String
    }
    type LinkConnection {
      pageInfo: PageInfo
      edges: LinkEdge
      count: Int
    }
    input LinkFilter {
      OR: [LinkFilter!]
      description_contains: String
      url_contains: String
    }
    }
  `;

PS:此语言架构是根据graphql-tools包完成的。

解析器:

 Query: {
        users: async (root, { first, after }, { mongo: { Users }, user }) => {
          const queryData = await Users.find(query).toArray();
          first = first || queryData.length;
          after = after ? parseInt(fromCursor(after), 10) : 0;
          const edges = queryData.map((node, i) => ({
            cursor: toCursor(i+1),
            node: node._id,
          })).slice(after, first + after);
          const slicedUser = edges.map(({ node }) => node);
          return {
            edges,
            pageInfo: {
              startCursor: edges.length > 0 ? edges[0].cursor : null,
              hasNextPage: first + after < queryData.length,
              endCursor: edges.length > 0 ? edges[edges.length - 1].cursor : null
            },
            count: queryData.length,
          };
        },
UserConnection: {
    edges: ({ edges }) => edges,
    pageInfo: ({ pageInfo }) => pageInfo,
    count: ({ count }) => count,
  },

  UserEdge: {
    node: async ({ node },data, {dataloaders: {userLoader}}) => {
      const user = await userLoader.load(node);
      return user;
    },
    cursor: ({ cursor }) => cursor,
  },

0 个答案:

没有答案