concept name in category graphql

appears as: name, The name, name, The names, names, names
GraphQL in Action

This is an excerpt from Manning's book GraphQL in Action.

The service can receive and parse any request. It will then try to validate the request against its schema. The schema has to support an employee field and that field has to represent an object that has an id argument, a name field, and an email field. Fields and arguments need to have types in GraphQL. The id argument can be an integer. The name and email fields can be strings. The employee field is a custom type (representing that exact id/name/email structure).

  • Write any non-default resolvers for the User type. Let’s combine the db first_name and last_name columns on table azdev.users into a single name field for the API.
  • Here’s a possible implementation of the new User type along with its non-default resolver for the name field:

    Listing 6.28. New file: api/src/schema/types/user.js
    import {
      GraphQLID,
      GraphQLObjectType,
      GraphQLString,
      GraphQLNonNull,
    } from 'graphql';
    
    const User = new GraphQLObjectType({
      name: 'User',
      fields: {
        id: { type: new GraphQLNonNull(GraphQLID) },
        username: { type: GraphQLString },
        name: {
          type: GraphQLString,
          resolve: ({ firstName, lastName }) =>
            `${firstName} ${lastName}`,
        },
      },
    });
    
    export default User;

    Note how for the resolve functions of the name field, I destructured the properties that are to be used in the resolver out of the first source argument.