[MGNLGQL-48] Sanitize content type names when creating GraphQL schemas Created: 19/Aug/20  Updated: 25/Mar/22

Status: Open
Project: Magnolia GraphQL
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Neutral
Reporter: Martin Drápela Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2020-08-19-09-59-05-377.png     PNG File image-2021-02-25-13-11-51-160.png     PNG File image.png    
Issue Links:
Problem/Incident
is caused by MGNLGQL-32 DOC: Create GraphQL endpoint page Closed
Template:
Acceptance criteria:
Empty
Task DoR:
Empty
Date of First Response:

 Description   

Problem description

Ever since DOCS57, we have been implicitly allowing dashes in content type filenames:

(https://documentation.magnolia-cms.com/display/DOCS62/Content+type+definition)

However, dashes create an issue for GraphQL schemas:

2020-08-19 08:48:51,572 ERROR info.magnolia.event.SimpleEventBus                : Exception caught when dispatching info.magnolia.graphql.core.GraphQLDefinitionChangedEvent with info.magnolia.graphql.core.GraphQLProvider$$Lambda$786/1987165365 eventHandler.
graphql.AssertException: Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]* - was 'Bookshelf-app'
	at graphql.Assert.assertValidName(Assert.java:107) ~[graphql-java-14.1.jar:?]
	at graphql.schema.FieldCoordinates.assertValidNames(FieldCoordinates.java:50) ~[graphql-java-14.1.jar:?]

https://spec.graphql.org/June2018/#sec-Names

(2.1.9 Names):

Name
/[_A-Za-z][_0-9A-Za-z]*/
GraphQL Documents are full of named things: operations, fields, arguments, types, directives, fragments, and variables. All names must follow the same grammatical form.

Names in GraphQL are case‐sensitive. That is to say nameName, and NAME all refer to different names. Underscores are significant, which means other_name and othername are two different names.

Names in GraphQL are limited to this ASCII subset of possible characters to support interoperation with as many other systems as possible.

 

Task

We should either:

  • Introduce a sanitizer for GraphQL schema generation in case a content type name contains dashes.
  • Or, let the users be aware of this and recommend some unifying best practice for (CT) name creation, such as resorting to camel case, the same way we do this for folder names:

 

 



 Comments   
Comment by Christopher Zimmermann [ 25/Feb/21 ]

The screenshots are a bit misleading "create-content-type" is not the name of the content type, it is the name of the CLI command. So I dont think there should be red underlingin of those - that is confusing, as it is not the problem.

Generated at Mon Feb 12 05:52:04 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.