in Education by
We have db collection which is little complicated. Many of our keys are JSON objects where fields aren't fixed and change based on input given by user on UI. How should we write mongoose and GraphQL Schema for such complex type ? { "_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") } Run code snippetExpand snippet I believe Mongoose have Mixed type but how do i represent such complex type in Apollo GraphQL Server and Mongoose Schema. Also, currently my resolver is just models.product.find(). So if i have such complex type, need to understand what update needs to make to my resolver. It will be great if i get complete solution for GraphQL Apollo schema, mongoose schema and resolver for my data. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Finally found solution for problem. You can declare new type and reference it in typeDef for GraphQL Schema. In mongoose model, you can reference it as {type: Array}

Related questions

0 votes
    I am trying to fetch some data from the GitHub GraphQL but I get a GaphQLError. I have tried the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    When I'm making a request to my backend through a mutation like that: mutation{ resetPasswordByToken(token:" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    What's the best practice (or tool) for updating/migrating Mongoose schemas as the application evolves? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    What's the best practice (or tool) for updating/migrating Mongoose schemas as the application evolves? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    The apollo basic example at https://www.apollographql.com/docs/apollo-server/features/data-sources.html#Implementing- ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I've been trying to send a cookie back to the client from the server. I get the response data ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    so i'm reviewing and practicing making rest api with node mongoose and express. I'm having problem making ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I have a Post model that has a likes array that contains the ObjectId of the user that liked the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I have an graphql/apollo-server/graphql-yoga endpoint. This endpoint exposes data returned from a database ( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    This is a cURL function that can send or retrieve data. It should work with any PHP app that ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I'm trying to query two JSON files that I put in a src/data directory. I installed gatsby- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I am working in an graphql application where I have to send custom error object / message in json ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I'm trying to query two JSON files that I put in a src/data directory. I installed gatsby- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    How can I transform QraphQl query to HTTP get request for example http://localhost:4000/? query GetClient { ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    What is the main difference between GraphQL and REST?...
asked Jun 13, 2021 in Education by Editorial Staff
...