I saw this statement in Graphql directive definition:
const { resolve = defaultFieldResolver } = field;
I know the part const { resolve } = field; means getting resolve property of the field object out and storing it in a local variable resolve. But what I'm coming across for the first time is the = defaultFieldResolver part. What does the equal sign do here? I've done a thorough google search but maybe I'm not aware of the right keyword to search or this is probably something new.
Here's the link of the article where I saw this.
Thanks a bunch.
That means if field contains a resolve property, extract it:
const defaultFieldResolver = 'defaultFieldResolver';
const field = { resolve: 'resolve' };
const { resolve = defaultFieldResolver } = field;
console.log(resolve);
If field doesn't contain a resolve property, assign defaultFieldResolver to the resolve variable instead.
const defaultFieldResolver = 'defaultFieldResolver';
const field = {};
const { resolve = defaultFieldResolver } = field;
console.log(resolve);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With