Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading documentation for 'resolveInput' for field hooks? #2508

Closed
ra-external opened this issue Mar 10, 2020 · 1 comment
Closed

Misleading documentation for 'resolveInput' for field hooks? #2508

ra-external opened this issue Mar 10, 2020 · 1 comment

Comments

@ra-external
Copy link

ra-external commented Mar 10, 2020

The documentation for resolveInput for field hooks seems a bit misleading. When it says

The return of resolveInput can be a Promise or an Object. It should resolve to the same structure as the resolvedData. The result is passed to the next function in the execution order.

and gives as an example

const resolveInput = ({
  operation,
  existingItem,
  originalInput,
  resolvedData,
  context,
  actions,
}) => {
  // Input resolution logic
  // Object returned is used in place of resolvedData
  return resolvedData;
};

instead it would seem that you can't return resolvedData but rather the field inside resolvedData for which you're writing a hook. For instance, in my Article list I had this field

text: {
                type: Wysiwyg,
                hooks: {
                    async resolveInput({ originalInput,resolvedData }) {
                        console.log('resolvedData');
                        console.log(resolvedData);
                        return resolvedData;
                    }
                }

but on saving the Article I kept getting this error within the AdminUI

GraphQLError
Cast to string failed for value "{ text: '<p><img src="static/blop.jpg" alt="" width="580" height="388" /><img src="static/blop.jpg" alt="" /></p>' }" at path "text"

The same thing happened when I used the resolveInput hook on another field,


title: {
				type: Text, schemaDoc: 'Title for published article',
                hooks: {
                    async resolveInput({ originalInput,resolvedData }) {
                        console.log('resolvedData');
                        console.log(resolvedData);
                        return resolvedData;
                    }
			}

thus it wasn't unique to theWysiwyg field type.

The solution was not to return resolvedData, but resolvedData.text (or resolvedData.title, respectively).

I think the docs should be changed, since the example at least doesn't make it clear what one should do.

@msalahat
Copy link

Thank you!

You saved my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants