Skip to content

Commit 65674bc

Browse files
alex-mcleodgregberge
authored andcommitted
feat: use xtend instead of Object.assign to ensure React Native compatibility (#6)
1 parent 551bff9 commit 65674bc

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,8 @@
7373
"path": "./dist/fraql.min.js",
7474
"maxSize": "2kb"
7575
}
76-
]
76+
],
77+
"dependencies": {
78+
"xtend": "^4.0.1"
79+
}
7780
}

src/mock.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
mergeSchemas,
1212
transformSchema,
1313
} from 'graphql-tools'
14+
import extend from 'xtend'
1415

1516
export function generateSchemaFromIntrospectionResult(introspectionResult) {
1617
const introspectionData = introspectionResult.data || introspectionResult
@@ -27,12 +28,11 @@ export function generateSchemaFromIntrospectionResult(introspectionResult) {
2728
) {
2829
return fields
2930
}
30-
return {
31-
...fields,
31+
return extend(fields, {
3232
[`fraql__${typeName}`]: {
3333
type: typeMap[typeName],
3434
},
35-
}
35+
})
3636
}, {})
3737

3838
const fraqlSchema = new GraphQLSchema({
@@ -84,7 +84,7 @@ export class Mocker {
8484
}
8585

8686
mockSchema({ mocks } = {}) {
87-
const mergedMocks = { ...this.mocks, ...mocks }
87+
const mergedMocks = extend(this.mocks, mocks)
8888
return mockSchema(this.schema, { mocks: mergedMocks })
8989
}
9090

@@ -97,10 +97,9 @@ export class Mocker {
9797
const schema = this.mockSchema(options)
9898
return Object.keys(fragmentDocuments).reduce((data, key) => {
9999
const fragmentDocument = fragmentDocuments[key]
100-
return {
101-
...data,
100+
return extend(data, {
102101
[key]: executeFragment(schema, fragmentDocument),
103-
}
102+
})
104103
}, {})
105104
}
106105
}

src/transform.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { print, Source } from 'graphql/language'
2+
import extend from 'xtend'
23

34
function inlineSpreadFragments(fragmentDefinitions, definition) {
45
if (definition.kind === 'FragmentSpread') {
@@ -10,12 +11,11 @@ function inlineSpreadFragments(fragmentDefinitions, definition) {
1011
return definition
1112
}
1213

13-
definition.selectionSet = {
14-
...definition.selectionSet,
14+
definition.selectionSet = extend(definition.selectionSet, {
1515
selections: definition.selectionSet.selections.map(selection =>
1616
inlineSpreadFragments(fragmentDefinitions, selection),
1717
),
18-
}
18+
})
1919

2020
return definition
2121
}
@@ -47,16 +47,14 @@ export function toInlineFragment(doc) {
4747
throw new Error('Unable to find a fragment definition')
4848
}
4949

50-
const newDoc = {
51-
...doc,
50+
const newDoc = extend(doc, {
5251
originalDocument: doc,
5352
definitions: [definition],
54-
}
53+
})
5554

56-
newDoc.loc = {
57-
...doc.loc,
55+
newDoc.loc = extend(doc.loc, {
5856
source: new Source(print(newDoc)),
59-
}
57+
})
6058

6159
return newDoc
6260
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5489,7 +5489,7 @@ xml-name-validator@^3.0.0:
54895489
version "3.0.0"
54905490
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
54915491

5492-
xtend@^4.0.0, xtend@~4.0.1:
5492+
xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.1:
54935493
version "4.0.1"
54945494
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
54955495

0 commit comments

Comments
 (0)