gentics / mesh

Gentics Mesh - The open source headless CMS for developers
https://getmesh.io
Apache License 2.0
572 stars 115 forks source link

Schema-Fieldname containing special chars causes graphql to fail #121

Open elbird opened 7 years ago

elbird commented 7 years ago

Gentics Mesh Version, operating system, or hardware.

Problem

If a schema or microschema contains a character which is not alphanumeric (or '_') all queries to graphql fail. With the following exception

15:03:53.951 [Dumbstruck Monferno] ERROR [vert.x-eventloop-thread-4] [FailureHandler.java:91] - Error for request in path: /api/v1/kofl/graphql/?null
15:03:53.952 [Dumbstruck Monferno] ERROR [vert.x-eventloop-thread-4] [FailureHandler.java:93] - Error:
graphql.AssertException: Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]*
        at graphql.Assert.assertValidName(Assert.java:35) ~[mesh-server-0.9.27.jar:na]
        at graphql.schema.GraphQLFieldDefinition.<init>(GraphQLFieldDefinition.java:35) ~[mesh-server-0.9.27.jar:na]
        at graphql.schema.GraphQLFieldDefinition$Builder.build(GraphQLFieldDefinition.java:215) ~[mesh-server-0.9.27.jar:na]
        at com.gentics.mesh.graphql.type.field.FieldDefinitionProvider.createStringDef(FieldDefinitionProvider.java:173) ~[mesh-server-0.9.27.jar:na]
        at com.gentics.mesh.graphql.type.field.MicronodeFieldTypeProvider.generateMicroschemaFieldType(MicronodeFieldTypeProvider.java:86) ~[mesh-server-0.9.27.
jar:na]
        at com.gentics.mesh.graphql.type.field.MicronodeFieldTypeProvider.createType(MicronodeFieldTypeProvider.java:49) ~[mesh-server-0.9.27.jar:na]
        at com.gentics.mesh.graphql.type.QueryTypeProvider.getRootSchema(QueryTypeProvider.java:436) ~[mesh-server-0.9.27.jar:na]
        at com.gentics.mesh.graphql.GraphQLHandler.handleQuery(GraphQLHandler.java:56) ~[mesh-server-0.9.27.jar:na]
        at com.gentics.mesh.graphql.GraphQLEndpoint.lambda$registerEndPoints$0(GraphQLEndpoint.java:50) ~[mesh-server-0.9.27.jar:na]
        at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:217) [mesh-server-0.9.27.jar:na]
        at io.v

And the following http-response body

{
  "message" : "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]*"
}

Expected behaviour

It should not be possible to add schemas or microschemas containing fieldnames with special chars. Alternatively the error message returned to the user should be more descriptive (containing the schema and fieldname where the error occurs)

Jotschi commented 7 years ago

Fieldnames with "." would most likely also cause issues with ES.