graphql-compose-elasticsearch icon indicating copy to clipboard operation
graphql-compose-elasticsearch copied to clipboard

Mappings with hyphens can't be parsed

Open clintandrewhall opened this issue 5 years ago • 3 comments

If the ES mapping property name contains a hyphen, the service cannot start. Is there a workaround?

    "comment-author-type": {
      type: "text",
      fields: {
        keyword: {
          type: "keyword",
          ignore_above: 256
        }
      }
    },
"errors": [
    {
      "message": "Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \"comment-author-type\" does not.",
      "stack": [
        "GraphQLError: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \"comment-author-type\" does not.",
        "    at isValidNameError (/Users/clint/Projects/chirp/node_modules/graphql/utilities/assertValidName.js:42:12)",
        "    at validateName (/Users/clint/Projects/chirp/node_modules/graphql/type/validate.js:199:53)",
        "    at validateInputFields (/Users/clint/Projects/chirp/node_modules/graphql/type/validate.js:439:5)",
        "    at validateTypes (/Users/clint/Projects/chirp/node_modules/graphql/type/validate.js:240:7)",
        "    at validateSchema (/Users/clint/Projects/chirp/node_modules/graphql/type/validate.js:54:3)",
        "    at /Users/clint/Projects/chirp/node_modules/express-graphql/index.js:97:66",
        "    at processTicksAndRejections (internal/process/task_queues.js:93:5)"
      ]
    },

clintandrewhall avatar Oct 22 '19 15:10 clintandrewhall

For now there is no mapping firlds with hyphens to camelCase.

There are two ways:

  • change ES field name to camelCase
  • dig lib code and open pull request

nodkz avatar Oct 25 '19 07:10 nodkz

same error image

Zhouchuanwen avatar Aug 20 '20 09:08 Zhouchuanwen

@Zhouchuanwen Nope, this package cannot translate numeric field names to graphql field names. And I don't know any workaround for that. Except you rename fields according to graphql field name convention. Or write your own resolver from scratch without graphql-compose-elasticsearch.

nodkz avatar Aug 21 '20 12:08 nodkz