Skip to content

Need examples for DRYer code patterns #426

Answered by hayes
miloofcroton asked this question in Q&A
Discussion options

You must be logged in to vote

Hey,

Not sure if I fully understand everything you are asking for here, so I created an interactive version of your example here: https://stackblitz.com/edit/typescript-nlswbq?file=resources/posts/objects.ts

Stack blitz doesn't load tsconfig correctly, so you will need to turn strict mode off and back on again before types are correct in the tsconfig when using the link above.

I added some logic to extract types from args defined in pothos:

You can define args separately like this:

export const getPostArgs = builder.args((t) => ({
  id: t.id({ required: true }),
}));

export const getPost = (t: PothosT) =>
  t.field({
    type: Post,
    nullable: true,
    args: getPostArgs,
    resolve: (

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@miloofcroton
Comment options

@miloofcroton
Comment options

@hayes
Comment options

Answer selected by hayes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #409 on June 17, 2022 17:30.