我无法使用mongo / mongoose / NO METEOR设置反应apollo mongodb app => resolvers

问题描述 投票:0回答:3

我正在学习阿波罗,我是一名前端开发人员(角度1.5半年以上的背景)我对mongodb的经验非常少,而且还有apollo(trhough a meteor app)

我已经多次阅读过Apollo文档,用关键字apollo,react,mongodb,resolvers,以及各种组合解析Google ...(没有结果)

我需要构建一个小的React应用程序(POC)来处理查询,突变和订阅,这些应用程序将使用mongodb(或另一个DB,我指示这个,因为这只是我迄今为止使用过的一个)来保存数据。

我不能使用Meteor。

我的问题是,我无法找到适合我需要的所有情况(查询,子,变异)的图形解析器使用mongo的正确示例。

你能提供一些样板来帮助我理解机制吗?

谢谢。

mongodb reactjs mongoose apollo
3个回答
0
投票

如果你不想通过一些教程。你可以看看githunt项目。它是一个带有查询,突变和订阅的apollo-graphql实现。它不使用mongoDB,但这应该是一个简单的改变。

服务器:https://github.com/apollographql/GitHunt-API/tree/master/api

客户:https://github.com/apollographql/GitHunt-React

干杯


0
投票

我认为graphqly是你的答案。

import graphly from "graphqly";

const gBuilder = graphly.createBuilder();

// define types, inputs ... (in any order)
gBuilder.type("Products").implements("List").def(`
  products: [Product]!
`);

gBuilder.type("Product").def(`
  id: ID!
  name: String!
  link: String
  price: Int
`);

// we're too lazy to define a separate input, so we can `extend` other structure
gBuilder.input("ProductInput").ext("Product");

gBuilder.enum("ProductOrder").def(`
  PRICE_DESCENDING
  PRICE_ASCENDING
  NEWEST
`);

// define interface `List`
gBuilder.iface("List").def(`
  total: Int!,
  offset: Int!,
  limit: Int!,
  # number of items actually in this window
  size: Int!
`);


gBuilder.query(`
  products(limit: Int = 20, offset: Int = 0, filter: ProductFilter): Products
`)
.resolve((root, args, context) => {
  // your resolver here
  // `this` is binded to the current Query instance
});

0
投票

所以,对于服务器而言,这是mongo / mongoose的良好开端:

https://github.com/khadorkin/apollo-server-mongoose

我已经增强了这一点,我将在几天内提供一个指向github repo的链接。

这是回购。仍有工作要做,特别是关于订阅,但它可能是一个良好的开端

Link to Github repo

© www.soinside.com 2019 - 2024. All rights reserved.