Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return passed-in value from mutation #80

Closed
LeeroyJenks opened this issue Oct 9, 2019 · 7 comments
Closed

Return passed-in value from mutation #80

LeeroyJenks opened this issue Oct 9, 2019 · 7 comments

Comments

@LeeroyJenks
Copy link

Thank you so much for this tool. It's really made it a lot easier for me to work in tandem with our back end team here and hopefully get projects out quicker.

I wanted to be able to have a mutation return the passed-in value.

For example, if I have a type Lead:

type Lead {
  id: ID @fake(type: uuid)
  status: String @examples(values:[ "New Lead", "In Communication" ])
}

And I extend my QueryRoot like so:

extend type QueryRoot {
	leads: [Lead] @listLength(min: 0, max:20)
}

And then extend my MutationRoot:

extend type MutationRoot {
  update_lead_status(lead_id:ID! status: String!): Lead
}

When I run the mutation:

mutation {
  update_lead_status(id: "2fe0df37-955d-4de2-bd50-d1176a1bd4c4" status: "New Lead") {
    id
    status
  }
}

It'll still return a random id and status. Is there a way to have it return the passed-in values instead? I want to mimmic a successful mutation of values and check some Apollo caching, which would at the very least require the id to be returned.

thanks!

@IvanGoncharov
Copy link
Member

@LeeroyJenks Thanks a lot for detail example 👍
Sorry for the delay, implemented in 2.0.0-rc.13 📦
Can you please test it?

@LeeroyJenks
Copy link
Author

LeeroyJenks commented Oct 21, 2019

@IvanGoncharov that was perfect, thank you! Works flawlessly now.

image

Although now when I set up a fake time like so:
submitted_at: Time @fake(type: pastDate)
I get an error on save:
Unknown type "Time".

Am I doing something wrong? Should I open another issue?

Edit:
Looking at the PR for this issue, it appears to be unrelated. Let me know if I'm doing something wrong or if I should open a new issue.

Thanks again! Extremely useful tool

@IvanGoncharov
Copy link
Member

@LeeroyJenks GraphQL doesn't define any type beyond Int, Float, ID, String and Boolean. For any other scalar type you need to define it:

scalar Time

@LeeroyJenks
Copy link
Author

I guess it was working before because I was extending an existing graphql endpoint.

Thank you!

@alecrae
Copy link
Contributor

alecrae commented Apr 9, 2020

@IvanGoncharov this fix appears to be affecting mutations that are not faked or have fields that are not faked ie passed straight through to a real graphql backend, I think it should only be applied to faked fields?

@IvanGoncharov
Copy link
Member

@alecrae Can you please report it as a separate issue and provide an example?

@alecrae
Copy link
Contributor

alecrae commented Apr 10, 2020

@IvanGoncharov sure thing, my colleague has done so in #97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants