|
1 | 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP |
2 | 2 |
|
| 3 | +exports[`macros [gql] should handle duplicated fragments (issue#90): [gql] should handle duplicated fragments (issue#90) 1`] = ` |
| 4 | +
|
| 5 | +import { gql } from 'graphql.macro'; |
| 6 | +const frag1 = gql\`fragment TestDuplicate on Bar { field }\`; |
| 7 | +const frag2 = gql\`fragment TestDuplicate on Bar { field }\`; |
| 8 | +const query = gql\`{ bar { fieldOne ...TestDuplicate } } \${frag1} \${frag2}\`; |
| 9 | +
|
| 10 | + ↓ ↓ ↓ ↓ ↓ ↓ |
| 11 | +
|
| 12 | +const frag1 = { |
| 13 | + "kind": "Document", |
| 14 | + "definitions": [{ |
| 15 | + "kind": "FragmentDefinition", |
| 16 | + "name": { |
| 17 | + "kind": "Name", |
| 18 | + "value": "TestDuplicate" |
| 19 | + }, |
| 20 | + "typeCondition": { |
| 21 | + "kind": "NamedType", |
| 22 | + "name": { |
| 23 | + "kind": "Name", |
| 24 | + "value": "Bar" |
| 25 | + } |
| 26 | + }, |
| 27 | + "directives": [], |
| 28 | + "selectionSet": { |
| 29 | + "kind": "SelectionSet", |
| 30 | + "selections": [{ |
| 31 | + "kind": "Field", |
| 32 | + "name": { |
| 33 | + "kind": "Name", |
| 34 | + "value": "field" |
| 35 | + }, |
| 36 | + "arguments": [], |
| 37 | + "directives": [] |
| 38 | + }] |
| 39 | + } |
| 40 | + }], |
| 41 | + "loc": { |
| 42 | + "start": 0, |
| 43 | + "end": 39, |
| 44 | + "source": { |
| 45 | + "body": "fragment TestDuplicate on Bar { field }", |
| 46 | + "name": "GraphQL request", |
| 47 | + "locationOffset": { |
| 48 | + "line": 1, |
| 49 | + "column": 1 |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +}; |
| 54 | +const frag2 = { |
| 55 | + "kind": "Document", |
| 56 | + "definitions": [{ |
| 57 | + "kind": "FragmentDefinition", |
| 58 | + "name": { |
| 59 | + "kind": "Name", |
| 60 | + "value": "TestDuplicate" |
| 61 | + }, |
| 62 | + "typeCondition": { |
| 63 | + "kind": "NamedType", |
| 64 | + "name": { |
| 65 | + "kind": "Name", |
| 66 | + "value": "Bar" |
| 67 | + } |
| 68 | + }, |
| 69 | + "directives": [], |
| 70 | + "selectionSet": { |
| 71 | + "kind": "SelectionSet", |
| 72 | + "selections": [{ |
| 73 | + "kind": "Field", |
| 74 | + "name": { |
| 75 | + "kind": "Name", |
| 76 | + "value": "field" |
| 77 | + }, |
| 78 | + "arguments": [], |
| 79 | + "directives": [] |
| 80 | + }] |
| 81 | + } |
| 82 | + }], |
| 83 | + "loc": { |
| 84 | + "start": 0, |
| 85 | + "end": 39, |
| 86 | + "source": { |
| 87 | + "body": "fragment TestDuplicate on Bar { field }", |
| 88 | + "name": "GraphQL request", |
| 89 | + "locationOffset": { |
| 90 | + "line": 1, |
| 91 | + "column": 1 |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | +}; |
| 96 | +const query = { |
| 97 | + "kind": "Document", |
| 98 | + "definitions": [{ |
| 99 | + "kind": "OperationDefinition", |
| 100 | + "operation": "query", |
| 101 | + "variableDefinitions": [], |
| 102 | + "directives": [], |
| 103 | + "selectionSet": { |
| 104 | + "kind": "SelectionSet", |
| 105 | + "selections": [{ |
| 106 | + "kind": "Field", |
| 107 | + "name": { |
| 108 | + "kind": "Name", |
| 109 | + "value": "bar" |
| 110 | + }, |
| 111 | + "arguments": [], |
| 112 | + "directives": [], |
| 113 | + "selectionSet": { |
| 114 | + "kind": "SelectionSet", |
| 115 | + "selections": [{ |
| 116 | + "kind": "Field", |
| 117 | + "name": { |
| 118 | + "kind": "Name", |
| 119 | + "value": "fieldOne" |
| 120 | + }, |
| 121 | + "arguments": [], |
| 122 | + "directives": [] |
| 123 | + }, { |
| 124 | + "kind": "FragmentSpread", |
| 125 | + "name": { |
| 126 | + "kind": "Name", |
| 127 | + "value": "TestDuplicate" |
| 128 | + }, |
| 129 | + "directives": [] |
| 130 | + }] |
| 131 | + } |
| 132 | + }] |
| 133 | + } |
| 134 | + }].concat(frag1.definitions, frag2.definitions).reduce((acc, definition) => definition.kind !== "FragmentDefinition" || acc.find(curDef => curDef.name.value === definition.name.value) ? acc : acc.concat(definition), []), |
| 135 | + "loc": { |
| 136 | + "start": 0, |
| 137 | + "end": 39, |
| 138 | + "source": { |
| 139 | + "body": "{ bar { fieldOne ...TestDuplicate } } ", |
| 140 | + "name": "GraphQL request", |
| 141 | + "locationOffset": { |
| 142 | + "line": 1, |
| 143 | + "column": 1 |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | +}; |
| 148 | +
|
| 149 | +`; |
| 150 | + |
3 | 151 | exports[`macros [gql] with fragment: [gql] with fragment 1`] = ` |
4 | 152 |
|
5 | 153 | import { gql } from 'graphql.macro'; |
@@ -114,7 +262,7 @@ const query = { |
114 | 262 | } |
115 | 263 | }] |
116 | 264 | } |
117 | | - }].concat(userFragment.definitions), |
| 265 | + }].concat(userFragment.definitions).reduce((acc, definition) => definition.kind !== "FragmentDefinition" || acc.find(curDef => curDef.name.value === definition.name.value) ? acc : acc.concat(definition), []), |
118 | 266 | "loc": { |
119 | 267 | "start": 0, |
120 | 268 | "end": 82, |
|
0 commit comments