Exclude nulls from serialized AST

This commit is contained in:
Vladimir Razuvaev 2018-01-13 16:15:18 +07:00
parent 8b17953fe5
commit 9944a689bf
5 changed files with 64 additions and 97 deletions

View File

@ -1,3 +1,39 @@
## Upgrade v0.10.x > dev-master
### Possibly Breaking: AST to array serialization excludes nulls
Most users won't be affected. It *may* affect you only if you do your own manipulations
with exported AST.
Example of json-serialized AST before the change:
```json
{
"kind": "Field",
"loc": null,
"name": {
"kind": "Name",
"loc": null,
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
}
```
After the change:
```json
{
"kind": "Field",
"name": {
"kind": "Name",
"value": "id"
},
"arguments": [],
"directives": []
}
```
## Upgrade v0.8.x, v0.9.x > v0.10.x
### Breaking: changed minimum PHP version from 5.4 to 5.5

View File

@ -131,7 +131,7 @@ abstract class Node
if (isset($result[$prop]))
continue;
if ($prop === 'loc' && $propValue === null)
if ($propValue === null)
continue;
if (is_array($propValue) || $propValue instanceof NodeList) {

View File

@ -3,6 +3,7 @@ namespace GraphQL\Language\AST;
/**
export type ValueNode = VariableNode
| NullValueNode
| IntValueNode
| FloatValueNode
| StringValueNode

View File

@ -24,8 +24,7 @@
"kind": "Name",
"value": "ComplexType"
}
},
"defaultValue": null
}
},
{
"kind": "VariableDefinition",
@ -95,10 +94,8 @@
"kind": "Name",
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
},
{
"kind": "InlineFragment",
@ -128,7 +125,6 @@
"kind": "Name",
"value": "field2"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -140,10 +136,8 @@
"kind": "Name",
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
},
{
"kind": "Field",
@ -216,10 +210,8 @@
"kind": "Name",
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
},
{
"kind": "FragmentSpread",
@ -240,7 +232,6 @@
},
{
"kind": "InlineFragment",
"typeCondition": null,
"directives": [
{
"kind": "Directive",
@ -275,17 +266,14 @@
"kind": "Name",
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
},
{
"kind": "InlineFragment",
"typeCondition": null,
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
@ -296,10 +284,8 @@
"kind": "Name",
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -328,7 +314,6 @@
"kind": "Name",
"value": "like"
},
"alias": null,
"arguments": [
{
"kind": "Argument",
@ -361,7 +346,6 @@
"kind": "Name",
"value": "story"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -373,10 +357,8 @@
"kind": "Name",
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -410,8 +392,7 @@
"kind": "Name",
"value": "StoryLikeSubscribeInput"
}
},
"defaultValue": null
}
}
],
"directives": [],
@ -424,7 +405,6 @@
"kind": "Name",
"value": "storyLikeSubscribe"
},
"alias": null,
"arguments": [
{
"kind": "Argument",
@ -451,7 +431,6 @@
"kind": "Name",
"value": "story"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -463,7 +442,6 @@
"kind": "Name",
"value": "likers"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -475,10 +453,8 @@
"kind": "Name",
"value": "count"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -489,7 +465,6 @@
"kind": "Name",
"value": "likeSentence"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -501,10 +476,8 @@
"kind": "Name",
"value": "text"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -541,7 +514,6 @@
"kind": "Name",
"value": "foo"
},
"alias": null,
"arguments": [
{
"kind": "Argument",
@ -595,17 +567,14 @@
}
}
],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
},
{
"kind": "OperationDefinition",
"name": null,
"operation": "query",
"variableDefinitions": null,
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
@ -616,7 +585,6 @@
"kind": "Name",
"value": "unnamed"
},
"alias": null,
"arguments": [
{
"kind": "Argument",
@ -651,8 +619,7 @@
}
}
],
"directives": [],
"selectionSet": null
"directives": []
},
{
"kind": "Field",
@ -660,10 +627,8 @@
"kind": "Name",
"value": "query"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}

View File

@ -56,8 +56,7 @@
},
"value": "ComplexType"
}
},
"defaultValue": null
}
},
{
"kind": "VariableDefinition",
@ -199,10 +198,8 @@
},
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
},
{
"kind": "InlineFragment",
@ -264,7 +261,6 @@
},
"value": "field2"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -288,10 +284,8 @@
},
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
},
{
"kind": "Field",
@ -440,10 +434,8 @@
},
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
},
{
"kind": "FragmentSpread",
@ -476,7 +468,6 @@
"start": 574,
"end": 614
},
"typeCondition": null,
"directives": [
{
"kind": "Directive",
@ -547,10 +538,8 @@
},
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -561,7 +550,6 @@
"start": 619,
"end": 639
},
"typeCondition": null,
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
@ -584,10 +572,8 @@
},
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -636,7 +622,6 @@
},
"value": "like"
},
"alias": null,
"arguments": [
{
"kind": "Argument",
@ -701,7 +686,6 @@
},
"value": "story"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -725,10 +709,8 @@
},
"value": "id"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -790,8 +772,7 @@
},
"value": "StoryLikeSubscribeInput"
}
},
"defaultValue": null
}
}
],
"directives": [],
@ -816,7 +797,6 @@
},
"value": "storyLikeSubscribe"
},
"alias": null,
"arguments": [
{
"kind": "Argument",
@ -871,7 +851,6 @@
},
"value": "story"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -895,7 +874,6 @@
},
"value": "likers"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -919,10 +897,8 @@
},
"value": "count"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -941,7 +917,6 @@
},
"value": "likeSentence"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": {
@ -965,10 +940,8 @@
},
"value": "text"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -1033,7 +1006,6 @@
},
"value": "foo"
},
"alias": null,
"arguments": [
{
"kind": "Argument",
@ -1143,8 +1115,7 @@
}
}
],
"directives": [],
"selectionSet": null
"directives": []
}
]
}
@ -1155,9 +1126,7 @@
"start": 1020,
"end": 1086
},
"name": null,
"operation": "query",
"variableDefinitions": null,
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
@ -1180,7 +1149,6 @@
},
"value": "unnamed"
},
"alias": null,
"arguments": [
{
"kind": "Argument",
@ -1251,8 +1219,7 @@
}
}
],
"directives": [],
"selectionSet": null
"directives": []
},
{
"kind": "Field",
@ -1268,10 +1235,8 @@
},
"value": "query"
},
"alias": null,
"arguments": [],
"directives": [],
"selectionSet": null
"directives": []
}
]
}