oak-graphql icon indicating copy to clipboard operation
oak-graphql copied to clipboard

Change resolver parameters to follow Deno styling

Open JIGutierrez opened this issue 4 years ago • 2 comments

Currently, resolver functions have a format of:

const myResolver = (parent: any, data: any, ctx: any, info: any) => { ... }

According to the Deno Style Guide exported functions should have at most two parameters, which in this case, should be one argument and an options object. Due to the frequent use of the data parameter, I propose doing something like this:

interface resolverOptions: {
  parent: any,
  context: any,
  info: any
};

const myResolver = (data: any, options: myResolver) => { ... }

This way, there will be no errors using deno lint (currently doesn't support custom flags), and will leave enough flexibility to use your own data interface, and extend the options interface to use your custom context (oak's RouterContext, for example).

Lastly, maybe the anys in the code could be changed to something safer? Perhaps Record<string, unknown> for data, not sure about the rest.

Thanks in advance :)

JIGutierrez avatar Jan 08 '21 20:01 JIGutierrez

Currently, resolver functions have a format of:

const myResolver = (parent: any, data: any, ctx: any, info: any) => { ... }

According to the Deno Style Guide exported functions should have at most two parameters, which in this case, should be one argument and an options object. Due to the frequent use of the data parameter, I propose doing something like this:

interface resolverOptions: {
  parent: any,
  context: any,
  info: any
};

const myResolver = (data: any, options: myResolver) => { ... }

This way, there will be no errors using deno lint (currently doesn't support custom flags), and will leave enough flexibility to use your own data interface, and extend the options interface to use your custom context (oak's RouterContext, for example).

Lastly, maybe the anys in the code could be changed to something safer? Perhaps Record<string, unknown> for data, not sure about the rest.

Thanks in advance :)

Typo: options: myResolver should be options: resolverOptions

borsemayur2 avatar Apr 08 '21 02:04 borsemayur2

Is it possible to change this? It seems like that is matching the resolver signature coming from GQL.

justinmchase avatar Jun 24 '21 00:06 justinmchase