Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Custom resolver "create" method types #2300

Closed
itsemirhanengin opened this issue Aug 20, 2021 · 3 comments
Closed

Custom resolver "create" method types #2300

itsemirhanengin opened this issue Aug 20, 2021 · 3 comments
Labels
question Further information is requested

Comments

@itsemirhanengin
Copy link

Hello! I'm trying to write a custom resolver for a reason. But when I try to use create method, I get this type error.
image

But when I ignore the error with // @ts-ignore I get no error and it works.
How can I make this without ignore the errors?

Thanks!

@itsemirhanengin itsemirhanengin added the question Further information is requested label Aug 20, 2021
@CoreyKovalik
Copy link
Collaborator

CoreyKovalik commented Aug 21, 2021

You are running into an issue we have been running into as well. This is because of how the crud service is typing the create method. Here's the solve I've been doing.

import { CreateUserInput, User } from "your-generated-types.ts";

// TypeScript will protect you here. careful not to use `as CreateUserInput`
const createPayload: CreateUserInput = {
    fullname: 'John Doe',
    email: 'email@domain.com',
    password: '12345',
    phone: '555-1234',
};

// you're casting "User" and basically telling TypeScript it's OK.
// this typically would be unsafe, but because you're typing it above, this should be acceptable :)
const user = await context.graphback.User.create(<User>createPayload);

@itsemirhanengin
Copy link
Author

Thank you so much @CoreyKovalik! I've just tried it and It works great.

@itsemirhanengin
Copy link
Author

image
@CoreyKovalik I don't know why but VS code started to give me this error...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants