当前位置: 首页 > 知识库问答 >
问题:

Mongoose+GraphQL(Apollo Server)模式

单于煌
2023-03-14
{
    "_id" : ObjectId("5ababb359b3f180012762684"),
    "item_type" : "Sample",
    "title" : "This is sample title",
    "sub_title" : "Sample sub title",
    "byline" : "5c6ed39d6ed6def938b71562",
    "lede" : "Sample description",
    "promoted" : "",
    "slug" : [ 
        "myurl"
    ],
    "categories" : [ 
        "Technology"
    ],
    "components" : [ 
        {
            "type" : "Slide",
            "props" : {
                "description" : {
                    "type" : "",
                    "props" : {
                        "value" : "Sample value"
                    }
                },
                "subHeader" : {
                    "type" : "",
                    "props" : {
                        "value" : ""
                    }
                },
                "ButtonWorld" : {
                    "type" : "a-button",
                    "props" : {
                        "buttonType" : "product",
                        "urlType" : "Internal Link",
                        "isServices" : false,
                        "title" : "Hello World",
                        "authors" : [ 
                            {
                                "__dataID__" : "Qm9va0F1dGhvcjo1YWJhYjI0YjllNDIxNDAwMTAxMGNkZmY=",
                                "_id" : null,
                                "First_Name" : "John",
                                "Last_Name" : "Doe",
                                "Display_Name" : "John Doe",
                                "Slug" : "john-doe",
                                "Role" : 1
                            }
                        ],
                        "isbns" : [ 
                            "9781497603424"
                        ],
                        "image" : "978-cover.jpg",
                        "price" : "8.99",
                        "bisacs" : [],
                        "customCategories" : [],
                },
                "salePrice" : {
                    "type" : "",
                    "props" : {
                        "value" : ""
                    }
                }
            }
        }, 
   "tags" : [ 
        {
            "id" : "5abab58042e2c90011875801",
            "name" : "Tag Test 1"
        }, 
        {
            "id" : "5abab5831242260011c248f9",
            "name" : "Tag Test 2"
        }, 
        {
            "id" : "592450e0b1be5055278eb5c6",
            "name" : "horror",
        }, 
        {
            "id" : "59244a96b1be5055278e9b0e",
            "name" : "Special Report",
            "_id" : "59244a96b1be5055278e9b0e"
        }
    ],
    "created_at" : ISODate("2018-03-27T21:44:21.412Z"),
    "created_by" : ObjectId("591345bda429e90011c1797e")
}

共有1个答案

乐正宜人
2023-03-14

终于找到了解决问题的办法。

您可以为GraphQL模式声明新类型并在typeDef中引用它。

在mongoose模型中,您可以将其引用为{type:Array}

 类似资料:
  • GraphQL Mongoose Cursor Pagination with Elasticsearch Support Adds support for Relay-like cursor pagination with Mongoose models/documents. This library also provides type-ahead (autocomplete) functio

  • GraphQL Mongoose Loader Install npm i @entria/graphql-mongoose-loader --saveyarn add @entria/graphql-mongoose-loader Mongoose Dataloader Batch Add batch to your GraphQL resolvers/loaders Define a mong

  • graphql-compose-mongoose This is a plugin for graphql-compose, which derives GraphQLType from your mongoose model. Also derives bunch of internal GraphQL Types. Provide all CRUD resolvers, including g

  • Koa 2 + Passport + Mongoose + GraphQL Notice You want build a more flexible GraphQL schema, consider using this boilerplate instead: https://github.com/sibelius/graphql-dataloader-boilerplate graffiti

  • 是否可以同时利用GraphQL和Mongoose? 到目前为止,我已经能够集成GraphQL和Mongoose来处理填充数据库,但是我很难理解这如何工作来检索数据,特别是具有嵌套引用的数据。 考虑这个模式: Bar模式本质上是相同的,只有一个“名称”字段。 是否可以运行GraphQL查询,用“bar”中的引用填充数据? 目前,我们正在使用GraphQL工具创建TypeDef、突变和查询,如下所示:

  • 我正在试验graphql,并使用graphql瑜伽创建了一个简单的服务器。我的Mongoose产品模型查询我的数据库,两个解析器按预期返回数据。到目前为止,一切顺利,我很高兴这是多么容易。然而,我有一个问题。我正在尝试添加一种方法来对来自graphQL的结果进行分页。 1) 向查询类型添加限制参数。 2) 通过解析器中的参数访问参数 我可以在我的解析器中使用args.limit参数并使用它来改变M