Skip to content

Commit

Permalink
feat: use xtend instead of Object.assign to ensure React Native compa…
Browse files Browse the repository at this point in the history
…tibility (#6)
  • Loading branch information
alex-mcleod authored and gregberge committed Oct 13, 2018
1 parent 551bff9 commit 65674bc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@
"path": "./dist/fraql.min.js",
"maxSize": "2kb"
}
]
],
"dependencies": {
"xtend": "^4.0.1"
}
}
13 changes: 6 additions & 7 deletions src/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
mergeSchemas,
transformSchema,
} from 'graphql-tools'
import extend from 'xtend'

export function generateSchemaFromIntrospectionResult(introspectionResult) {
const introspectionData = introspectionResult.data || introspectionResult
Expand All @@ -27,12 +28,11 @@ export function generateSchemaFromIntrospectionResult(introspectionResult) {
) {
return fields
}
return {
...fields,
return extend(fields, {
[`fraql__${typeName}`]: {
type: typeMap[typeName],
},
}
})
}, {})

const fraqlSchema = new GraphQLSchema({
Expand Down Expand Up @@ -84,7 +84,7 @@ export class Mocker {
}

mockSchema({ mocks } = {}) {
const mergedMocks = { ...this.mocks, ...mocks }
const mergedMocks = extend(this.mocks, mocks)
return mockSchema(this.schema, { mocks: mergedMocks })
}

Expand All @@ -97,10 +97,9 @@ export class Mocker {
const schema = this.mockSchema(options)
return Object.keys(fragmentDocuments).reduce((data, key) => {
const fragmentDocument = fragmentDocuments[key]
return {
...data,
return extend(data, {
[key]: executeFragment(schema, fragmentDocument),
}
})
}, {})
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/transform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { print, Source } from 'graphql/language'
import extend from 'xtend'

function inlineSpreadFragments(fragmentDefinitions, definition) {
if (definition.kind === 'FragmentSpread') {
Expand All @@ -10,12 +11,11 @@ function inlineSpreadFragments(fragmentDefinitions, definition) {
return definition
}

definition.selectionSet = {
...definition.selectionSet,
definition.selectionSet = extend(definition.selectionSet, {
selections: definition.selectionSet.selections.map(selection =>
inlineSpreadFragments(fragmentDefinitions, selection),
),
}
})

return definition
}
Expand Down Expand Up @@ -47,16 +47,14 @@ export function toInlineFragment(doc) {
throw new Error('Unable to find a fragment definition')
}

const newDoc = {
...doc,
const newDoc = extend(doc, {
originalDocument: doc,
definitions: [definition],
}
})

newDoc.loc = {
...doc.loc,
newDoc.loc = extend(doc.loc, {
source: new Source(print(newDoc)),
}
})

return newDoc
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5489,7 +5489,7 @@ xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"

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

Expand Down

0 comments on commit 65674bc

Please sign in to comment.