garph icon indicating copy to clipboard operation
garph copied to clipboard

Helper methods: `resolve`

Open mishushakov opened this issue 1 year ago • 6 comments

Specify resolvers directly in schema

Example:

g.type('Query', {
  test: g.string().resolve(() => 'Hello World')
})

mishushakov avatar Mar 09 '23 15:03 mishushakov

Wouldn't this become a problem on the client? Since the runtime type information is required to initialize the client. Isn't it safe to say that type and resolve code fundamentally always must be separated to prevent the client from accidentally bundling server code?

Example:

import thing from "huge-server-side-library";

g.type('Query', {
  test: g.string().resolve(() => `Hello World: ${thing.computeSomething()}`)
})

kasper573 avatar Apr 11 '23 09:04 kasper573

Great question. I will have to investigate this

mishushakov avatar Apr 11 '23 10:04 mishushakov

@mishushakov any update?

raja-OX avatar May 07 '23 06:05 raja-OX

Not yet, is this important for you? Why doesn't the existing solution suffice?

mishushakov avatar May 07 '23 09:05 mishushakov

@mishushakov No problem in existing solution but I have issues with schema declarations in separate files. Have difficulties in schema declarations in separate files.

g.type('Query', {
  test: g.string().resolve(() => 'Hello World')
})

If I have solution like above it will be easy for schema declarations in separate files.

raja-OX avatar May 09 '23 05:05 raja-OX

@ksandin We have now shipped a babel plugin, that will compile some of the runtime information to static artefacts. Of course, we are still exploring other ways to work around that and would love to have your feedback!

https://github.com/stepci/garph-gqty#using-the-babel-plugin-alpha

mishushakov avatar May 17 '23 12:05 mishushakov