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

persist/push: Avoid sending object properties not declared in input types #120

Closed
johnrix opened this issue Sep 1, 2019 · 10 comments
Closed
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@johnrix
Copy link

johnrix commented Sep 1, 2019

Currently when pushing an object back to my GraphQL API, I can control the name of the input type for the update request handily using the adapter method getInputTypeName.

However, despite returning the name of an input type that is defined in my schema, the plugin encodes all values of my object into the push request rather than just those defined in the input type.

Using the example from the documentation, if my updatePost mutation only allowed changes to the content and title, but not the user, my schema might look something like this:

type Post {
    id: ID!
    userId: ID!
    title: String
    content: String
    ....
}

input PostInput {
    title: String
    content: String
}

type Mutation {
    updatePost(id: Int!, post: PostInput!): Post
}

However, if I tried to $push() an existing post, I will get an error from the GraphQL server, since all of the Post properties are getting encoded in the Input object, despite the input type only having title and content fields.

@cwirz
Copy link
Contributor

cwirz commented Sep 9, 2019

@johnrix how bout when you are able to mark fields as read only in the model structure?
currently having the same issue and i dont want to define the fields in the backend mutation without usage.

@johnrix
Copy link
Author

johnrix commented Sep 10, 2019

@cwirz, is there a way to flag a field as read-only within Vuex-ORM or using the graphql plugin? That would likely be one way to get around the problem if so. I can't find it right now if it exists though.

Currently, my only option is to use a model-related custom mutation.

@cwirz
Copy link
Contributor

cwirz commented Sep 11, 2019

@johnrix ok ill try to implement that when i have time

@johnrix
Copy link
Author

johnrix commented Sep 11, 2019

Sorry, I thought you were suggesting there was some way to do that already.

As I said, it would be one way around the issue. It seems sub-optimal to me though. Is it not possible simply to only include fields that are defined in the mutation Input type? This would then require no specific effort to flag read-only fields within the client-side model definitions.

@cwirz
Copy link
Contributor

cwirz commented Sep 12, 2019

@johnrix yeah agree since the system anyway requests the schema from the server. but for me the virtual field functionality is not even working: https://vuex-orm.github.io/plugin-graphql/guide/virtual-fields.html and i can find the code where the check if a field is present in the schema. does it work for you?

@johnrix
Copy link
Author

johnrix commented Sep 12, 2019

To be honest, I haven't tried the virtual field functionality, since I want the data to be fetched, but just not sent back in mutations. I'd be happy to have a go at this update myself also, if somebody can point me to the right location!

johnrix pushed a commit to johnrix/plugin-graphql that referenced this issue Dec 13, 2019
@ghost
Copy link

ghost commented May 18, 2020

Don't mean to bump this old thread, was this ever looked into @phortx or is there a way in the current configuration that allows for selecting which model fields are included in a mutation?

@phortx
Copy link
Collaborator

phortx commented May 25, 2020

That's a good point. I don't think this is possible currently. Maybe I can take a look in the future Feel free to create a Pull Request :)

@phortx
Copy link
Collaborator

phortx commented May 28, 2020

Good News:

This is an issue in my current project too. The best reason to tackle that ;)

I'll provide a patch this week.

@phortx phortx self-assigned this May 28, 2020
@phortx phortx added this to the 1.0.0 milestone May 28, 2020
@phortx phortx added the enhancement New feature or request label May 28, 2020
@phortx
Copy link
Collaborator

phortx commented May 29, 2020

This should be fixed in version 1.0.0-rc.39.

@phortx phortx closed this as completed May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants