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 ## Upgrade v0.8.x, v0.9.x > v0.10.x
### Breaking: changed minimum PHP version from 5.4 to 5.5 ### Breaking: changed minimum PHP version from 5.4 to 5.5

View File

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

View File

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

View File

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

View File

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