documentation icon indicating copy to clipboard operation
documentation copied to clipboard

[Bug]: via GraphQL valid JSON cannot be sent to populate JSON field in collection

Open zwingliernst opened this issue 3 years ago • 3 comments

Link to the documentation page or resource

https://github.com/strapi/strapi/blob/main/api-tests/plugins/graphql/crud.test.api.js#L29C7-L29C7

Describe the bug

a strapi field of type JSON i.e. attributes: {json_field: {type: 'json'}} cannot be filled through graphql with valid json.

a graphql containing this field reference: { data: { json_field: {"testkey": true}}

returns the error Strapi GraphQLError: Syntax Error: Expected Name, found String. This is a perfectly valid field-content and it's acutally the type of JSON one gets from JSON.Parse (keys have double-quotes like in the JSON definition)

Additional context

No response

Suggested improvements or fixes

GraphQL needs to be able to consume valid JSON with keys wrapped in double-quotes.

Related issue(s)/PR(s)

No response

zwingliernst avatar Sep 24 '23 08:09 zwingliernst

The current workaround is to use a replace function to remove the double-quotes. This is the Regex we use to identify keys and remove its double quotes. .replace(^(")"]+[^\\"]+)":/g, '$1:');

But this is ridiculous as a solution, since we work with valid JSON and GraphQL in other projects is easily able to consume valid JSON

zwingliernst avatar Sep 24 '23 08:09 zwingliernst

@zwingliernst Seems to me like this is not documentation related but main code base related please put the issue in https://github.com/strapi/strapi/issues

Boegie19 avatar Sep 24 '23 14:09 Boegie19

I'm sorry you're having trouble with the GraphQL plugin, @zwingliernst, but as our community member Boegie19 mentioned, this is a product issue, not a documentation issue. So please create the issue in the strapi/strapi repo as requested.

I will now close this documentation issue.

pwizla avatar Sep 26 '23 14:09 pwizla