Kashuab / mobx-depot

Scaffold MobX-powered models, queries and mutations with your GraphQL schema.
https://mobx-depot.dev
MIT License
8 stars 0 forks source link

Implement functions that pull input data from provided argument #30

Open Kashuab opened 1 year ago

Kashuab commented 1 year ago

The problem with the current implementation in regards to mutation/query args is that you could provide an object that matches the signature of the input type, while accidentally over-saturating the request which would result in a GraphQL error.

For example:

// Imagine this isn't a new post, but came from a query
const post = new PostModel({
  id: 'asdf',
  title: 'blah',
  content: 'beep-boop',
});

const mutation = new UpdatePostMutation({ id: 'asdf', post });

mutation.mutate()

In this case, the updatePost mutation accepts a post within UpdatePostInput, containing title and content but NOT id, as that's a separate argument. This code is type-safe but would produce a GraphQL error at runtime. Ideally, there would be auto-generated functions that would gatekeep what data goes into the mutation/query args.

For example:

const mutation = new UpdatePostMutation(
  filterUpdatePostMutationInput({ id: 'asdf', post })
);

Ideally, this implementation detail would be taken care of by the auto-generated mutations/queries. Actually, no, I think this should be manually implemented. Trying to do too much "automatically" could make the code hard to understand when taken at face value.