Skip to content

Commit

Permalink
Added variable support to mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
cfpinto committed Nov 10, 2020
1 parent 2afa14e commit b3ecd13
Show file tree
Hide file tree
Showing 6 changed files with 431 additions and 46 deletions.
86 changes: 58 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ $hero = new GraphQL\Graph('hero');
echo $hero->use('name')
->friends
->use('name')
->query();
->root()
->query();
```

will generate
Expand All @@ -40,7 +41,8 @@ $hero = new GraphQL\Graph('hero');
echo $hero->use('name')
->friends(['first'=>2])
->use('name')
->query();
->root()
->query();
```
will generate
```text
Expand All @@ -65,6 +67,7 @@ echo $hero->use('name')
->prev()
->costumes
->color
->root()
->query();
```
will generate
Expand Down Expand Up @@ -98,6 +101,7 @@ echo $hero->use('name')
->prev()
->costumes
->color
->root()
->query();
```
Will generate
Expand All @@ -121,31 +125,6 @@ Will generate
}
```

#### Mutations
After you chose your Hero and he takes you as his sidekick he will let you do some help him with some of his daily routine.
He might even let you choose his costume color. How cool is that?

```php
$mutation = new GraphQL\Mutation('changeHeroCostumeColor', ['id' => 'theHeroId', 'color'=>'red']);
echo $mutation
->hero
->use('name')
->costumes
->use('color')
->query();
```
Will generate
```text
mutation changeHeroCostumeColor(id: 'theHeroId', color: 'red') {
hero {
name
costumes {
color
}
}
}
```

#### Aliases
For the element of surprise, you might need to name some of the hero's properties differently; You might want to call
friends as partners_in_good or name as call_me_this
Expand All @@ -160,6 +139,7 @@ echo $hero->use('name')
->prev()
->costumes
->color
->root()
->query();
```
will generate
Expand Down Expand Up @@ -188,6 +168,7 @@ $fragment = new GraphQL\Fragment('properties', 'Hero');
$fragment->use('id', 'age');
$hero = new GraphQL\Graph('hero');
echo $hero->use('name', $fragment)->query();
echo $fragment->query();
```
will generate
```text
Expand Down Expand Up @@ -222,7 +203,6 @@ query getGraph($name: String){
}
```

### Coming Soon
#### Meta fields
you can also use meta fields the same way you would request a property

Expand Down Expand Up @@ -264,6 +244,56 @@ query getGraph($name: String){
}
```

#### Mutations
After you chose your Hero and he takes you as his sidekick he will let you do some help him with some of his daily routine.
He might even let you choose his costume color. How cool is that?

```php
$mutation = new GraphQL\Mutation('changeHeroCostumeColor', ['id' => 'theHeroId', 'color'=>'red']);
$mutation
->hero
->use('name')
->costumes
->use('color')
->root()
->query();
```
Will generate
```text
mutation changeHeroCostumeColor(id: 'theHeroId', color: 'red') {
hero {
name
costumes {
color
}
}
}
```
With variables
```php
$mutation = new GraphQL\Mutation('changeHeroCostumeColor', ['id' => new GraphQL\Variable('uuid', 'String', ''), new GraphQL\Variable('color', 'String', '')]);
$mutation
->hero
->use('name')
->costumes
->use('color')
->root()
->query();
```
Will generate
```text
mutation ChangeHeroCostumeColorMutation($uuid: String, $color: String) {
changeHeroCostumeColorAction(id: $uuid, color: $color) {
hero {
name
costumes {
color
}
}
}
}
```

## Support on Beerpay
Hey dude! Help me out for a couple of :beers:!

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^8"
"phpunit/phpunit": "^8",
"symfony/var-dumper": "^5.1"
}
}
Loading

0 comments on commit b3ecd13

Please sign in to comment.