Closed johnrix closed 4 years ago
@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.
@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.
@johnrix ok ill try to implement that when i have time
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.
@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?
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!
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?
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 :)
Good News:
This is an issue in my current project too. The best reason to tackle that ;)
I'll provide a patch this week.
This should be fixed in version 1.0.0-rc.39.
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: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.