graphql / graphql-js

A reference implementation of GraphQL for JavaScript
http://graphql.org/graphql-js/
MIT License
20.02k stars 2.02k forks source link

Graphql embbeded document having column with ObjectId reference #3646

Open Arifkhan71 opened 2 years ago

Arifkhan71 commented 2 years ago

Questions regarding how to use GraphQL

We want to keep signal strong in the GitHub issue tracker – to make sure that it remains the best place to track bugs and features that affect development.

If you have a question on how to use GraphQL, please post it to Stack Overflow with the tag #graphql.

Please do not post general questions directly as GitHub issues. They may sit for weeks unanswered, or may be spontaneously closed without answer.

Reporting issues with GraphQL.js

Before filing a new issue, make sure an issue for your problem doesn't already exist.

The best way to get a bug fixed is to provide a pull request with a simplified failing test case (or better yet, include a fix).

Feature requests

GraphQL.js is a reference implementation of the GraphQL specification. To discuss new features which are not GraphQL.js specific and fundamentally change the way GraphQL works, open an issue against the specification.

Security bugs

Facebook has a bounty program for the safe disclosure of security bugs. With that in mind, please do not file public issues; go through the process outlined on that page.

Arifkhan71 commented 2 years ago

I have created Graphql mongodb model as below

Feed Model

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const feeditemSchema = new Schema({

feeding: {type: Schema.Types.ObjectId,ref: 'Farmintake'},
mesunit: {type: String},
qty: { type: Number },
description:{ type: String },
remarks:{ type: String }

});

const feedSchema = new Schema({ feedname:{ type: String }, feedtime:{ type: String }, feedformula:[ feeditemSchema ], description:{ type: String }, creator: {type: Schema.Types.ObjectId,ref: 'User'} },{ timestamps: true });

module.exports = mongoose.model( 'Feed', feedSchema );

Farmintake Model

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const farmintakeSchema = new Schema({ name:{ type: String, required: true }, itmtype:{ type: String,

    required: true
},
madein:{
    type: String,
    required: true
},
mesunit:{
    type: String
},
usage:{
    type: String
},
remarks:{
    type: String
},

creator: {
    type: Schema.Types.ObjectId,
    ref: 'User'
}

},{ timestamps: true} );

module.exports = mongoose.model('Farmintake',farmintakeSchema); My types are:

type Feeditem{ _id: ID! feeding: Farmintake! mesunit: String! qty: Float! description: String remarks: String

}

type Feed{ _id: ID! feedname: String feedtime: String feedformula:[Feeditem] description: String creator: User! }

type Farmintake { _id: ID! name: String! itmtype: String! madein: String mesunit: String usage: String remarks: String creator: User! }

Some help me to create this model Query resolver.

Arifkhan71 commented 2 years ago

Using following query i am able to get data. My query

query{ feeds{ _id feedname feedtime description feedformula{ feeding{ _id } qty mesunit description remarks

}

} } Query Result

{ "data": { "feeds": [ { "_id": "62a98db16f3c47085003ae99", "feedname": "Dana", "feedtime": "Evening", "description": "Evening feed for Goat", "feedformula": [ { "feeding": { "_id": "62323da6109749e4a4f499f9" }, "qty": 1.5, "mesunit": "Kg", "description": "Testing Goat Feed", "remarks": "1st Goat Feed" } ] } ] } }

but what should i do to include the farmintake data within this query? please Help.