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

Support mutations #16

Closed
cdroulers opened this issue Apr 13, 2016 · 6 comments
Closed

Support mutations #16

cdroulers opened this issue Apr 13, 2016 · 6 comments
Milestone

Comments

@cdroulers
Copy link

Hey guys!

Just started looking into GraphQL and your project looks great! I was wondering if there were short term plans for mutation support. I'm looking into creating a project that would do CQRS via GraphQL and this framework looks good but lacks mutation for now!

@chkimes
Copy link
Owner

chkimes commented Apr 13, 2016

Thanks for the issue!

Mutations are definitely in the plans, though I've been thinking about the best way to represent them in the API. There are a few changes to the current API that we've also been planning since all the additional features we want to add won't fit easily into the current Fluent interface.

However, if you're eager to try the library I can probably get rudimentary mutation support working before the end of the week. I should note that this is definitely still an alpha version so the API may change significantly between releases.

@cdroulers
Copy link
Author

There's no rush for mutations. I'm starting with querying first and will end up with mutations in two or three weeks.

I already assumed this was alpha with the quantity of commits coming in!

@andyroper
Copy link

Hi,

I've just been playing with this project - any news on mutations support, It would be awesome!

@chkimes
Copy link
Owner

chkimes commented Jun 29, 2016

Hey Andy,

I apologize that development of this project has slowed recently as I've
gotten busy with other things. I do have a pretty good idea of how I want
to handle mutations, I just need to get some time in front of the keyboard
to do it.

I'll work on getting mutations implemented within the next few days and
then push a new version to NuGet.

-Chad

On Wed, Jun 29, 2016, 11:30 AM andyroper notifications@github.com wrote:

Hi,

I've just been playing with this project - any news on mutations support,
It would be awesome!


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#16 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AB2KwlOVCHJnOQldgu31x_YBqVEGEYsQks5qQo96gaJpZM4IGori
.

chkimes added a commit that referenced this issue Jun 30, 2016
@chkimes
Copy link
Owner

chkimes commented Jun 30, 2016

Mutations have landed (in dev)!

The API is similar to the explicit query API. This is pretty much a requirement since we have to specify both a name and an explicit argument shape. I'll copy an example from the tests for this feature:

schema.AddMutation("mutate",
    new {id = 0, newVal = 0},
    (db, args) => db.MutateMes.AsQueryable().FirstOrDefault(a => a.Id == args.id),
    (db, args) =>
    {
        var mutateMe = db.MutateMes.First(m => m.Id == args.id);
        mutateMe.Value = args.newVal;
        db.SaveChanges();
    });

Going through it one by one, the first line specifies the name. The second specifies the shape of the arguments (used in the (db, args) functions). The third line is the query that will be executed after the mutation is completed. The fourth line(s) is the actual mutation, which is just a function to be executed given the Context and your arguments as parameters.

It's unfortunate that in this case (and I think probably in many others) that the query to be executed is an exact duplicate of an already defined query. I'm considering ways to improve that, but it's a bit difficult given that the arguments shape for a mutation is unlikely to be reused.

Again copying from the tests, the results of executing this look like:

var results = gql.ExecuteQuery("mutation { mutate(id:1,newVal:5) { id, value } }");
Test.DeepEquals(results, "{ mutate: { id: 1, value: 5 } }");

var results2 = gql.ExecuteQuery("mutation { mutate(id:1,newVal:123) { id, value } }");
Test.DeepEquals(results2, "{ mutate: { id: 1, value: 123 } }");

@andyroper
Copy link

Excellent - Thanks!

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