Почему результат полей всегда null. Первый запуск.
код ошибки
\\\\\
код schema.js
const graph = require('graphql');
const {GraphQLObjectType,GraphQLString,GraphQLSchema,GraphQLID,GraphQLInt,GraphQLList} = graph;
let Directors = [
{'id':"1",'name':'Zigfrid',},
{'id':"2",'name':'Fill'},
];
const DirectorSome = new GraphQLObjectType({
name:'Director',
fields: ()=>({
id: {type:GraphQLString},
name: {type:GraphQLString},
}),
});
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
direct: {
type: DirectorSome,
args:{id:{type: GraphQLString}},
resolve(parent,args){
return Directors.filter((arr)=>(arr.id === args.id));
}
},
}
});
module.exports = new GraphQLSchema({
query: Query,
});
\\\\\\
Код сервера
const express = require('express');
const mongoose = require('mongoose');
const graphQlHTTP = require('express-graphql')
const schema = require('./server/schema/schema');
const app = express();
app.use('/graphql',graphQlHTTP({
schema,
graphiql:true,
}));
let start = async ()=>{
try{
let server = app.listen(0,()=>{console.log(`SERVER START ON PORT${server.address().port}`)})
}
catch(e){
console.log(`Error in start server`,e.message);
}
}
start();