javascript – GraphQL field with space

The GraphQL specification requires that names of things (fields, types, arguments, etc.) only contain letters, numbers and underscores. A field name cannot contain a space because spaces and other whitespace are used to separate individual tokens. In other words, one or more spaces or line returns are used to indicate that, for example, one field’s name has terminated and another has begun.

If your underlying data layer is returning data with keys that contain spaces, you need to define a field with an allowed name (like pokeball) and then write a resolver for that field. For example:

const UserItems = new GraphQLObjectType({
  name: "UserItems",
  fields: () => ({
    pokeball: {
      type: Pokeball,
      resolve: (parent) => {
        // The parent value will be whatever the parent field resolved to.
        // We look for a property named "Poke ball" on that value and return it.
        return parent["Poke ball"];
      },
    },
    ...
  }),
});

Read more here: Source link