obj =[{
id: 1,
name: "qwe",
img: [
{id: 1, name: "img1"},
{id: 2, name: "img2"},
{id: 3, name: "img3"},
]
}]
{
user(id:1){
id name
img{id name }
}
}
{
"id": 1,
"name": "qwe",
"img": {
"id": null
}
}
{
"id": 1,
"name": "qwe",
"img":[
{id: 1, name: "img1"},
{id: 2, name: "img2"},
{id: 3, name: "img3"}
]
}
const graphql = require('graphql');
const img = new graphql.GraphQLObjectType({
name: "img",
fields: () => {
return {
id: {type: graphql.GraphQLInt},
idUser: {type: graphql.GraphQLInt},
name: {type: graphql.GraphQLString}
}
}
})
const user = new graphql.GraphQLObjectType({
name: 'user',
description: 'This represents a Person',
fields: () => {
return {
id: {
type: graphql.GraphQLInt,
resolve (res) {
return res.id;
}
},
mail: {
type: graphql.GraphQLString,
resolve (res) {
return res.mail;
}
},
password: {
type: graphql.GraphQLString,
resolve (res) {
return "privat info";
}
},
name: {
type: graphql.GraphQLString,
resolve (res) {
return res.name;
}
},
img: {
type: new graphql.GraphQLList(img),
}
};
}
});
module.exports = user;
const graphql = require('graphql');
const userSchema = require("../schema/userSchema")
module.exports = {
type: new graphql.GraphQLList(userSchema),
args: {
id: {type: new graphql.GraphQLNonNull(graphql.GraphQLInt)}
},
resolve (source, args, context) {
return [
{
id: 123,
name: "pero",
img:
[
{id: 1, name: "pero111"},
{id: 2, name: "pero112"},
{id: 3, name: "pero113"}
]
}
]
}
}