enonic / lib-guillotine

Apache License 2.0
3 stars 0 forks source link

generateFormItemResolveFunction should return null if env.source[formItem.name] is undefined #24

Closed abdavid closed 4 years ago

abdavid commented 5 years ago

https://github.com/enonic/lib-guillotine/blob/43f527927657929ba952a9b8eff24b787b8d1502/src/main/resources/lib/guillotine/content-types.js#L307

From my understanding of graphQL a value should always be returned even if the there is no value.

I am currently using latest Apollo client to query an application using lib-guillotine, and when e.g. defining a field that might not exist like the caption on media_Image_Data this will cause Apollo to void the render, and in SSR applications this would kill the whole server. This happens due to memory cache consolidation in Apollo client.

Is there any reason not to return a null value when asking for a value defined by the schema but does not exist? Or is there any other place that might filter out null values in the library?

-- David

GlennRicaud commented 4 years ago

You are right about the null and the specifications clearly state so. This problem is due to the way the result is returned after the execution (based on the way Enonic XP maps back objects, omitting null values). We will fix it. Thank you for reporting :+1:

GlennRicaud commented 4 years ago

Fixed in lib-graphql:1.1.1 lib-guillotine:4.1.2 and app-guillotine:4.1.2

If you are using lib-guillotine, please use JSON.stringify when returning the result. Otherwise the null values will be omitted there also.

exports.post = function (req) {
 var body = JSON.parse(req.body);
 var result = graphQlLib.execute(schema, body.query, body.variables);
 return {
     contentType: 'application/json',
     body: JSON.stringify(result)
 };
};