Схема:
const graphql = require('graphql');
const _ = require('lodash');
const {
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLSchema
} = graphql;
const users = [
{ id: '23', firstName: 'Bill', age: 20 },
{ id: '47', firstName: 'Samantha', age: 21 }
]
const UserType = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: GraphQLString },
firstName: { type: GraphQLString },
age: {type: GraphQLInt },
}
});
const RootQueryType = new GraphQLObjectType({
name: 'RootQuery',
fields: {
user: {
type: UserType,
args: { id: {type: GraphQLString} },
resolve(parentValue, args) {
return _.find(users, args.id);
}
}
}
});
module.exports = new GraphQLSchema({
query: RootQueryType,
});
Выражать:
const express = require('express');
const expressGraphQL = require('express-graphql');
const schema = require('./schema/schema')
const app = express();
app.use('/graphql', expressGraphQL({
schema,
graphiql: true,
}));
app.listen(4000, () => {
console.info('Listening');
});
Запрос:
{
user(id:"23") {
id,
firstName,
age
}
}
Пытаюсь изучить GraphQL и не могу понять, что не так с моим запросом / схемой.


Вам просто нужно изменить способ вызова lodash's find:
return _.find(users, { id: args.id });
О боже, я иногда тупой. Я на самом деле очень хорошо знаю lodash и смотрел на все, кроме lodash lol.