graphql-compose / graphql-compose-elasticsearch

Hide Elastic Search REST API behind GraphQL.
https://graphql-compose.herokuapp.com/elasticsearch/
MIT License
583 stars 77 forks source link

Mappings with hyphens can't be parsed #74

Open clintandrewhall opened 5 years ago

clintandrewhall commented 5 years ago

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)"
      ]
    },
nodkz commented 4 years ago

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

There are two ways:

Zhouchuanwen commented 4 years ago

same error image

nodkz commented 4 years ago

@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.