graphql-component
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -0,1 +1,5 @@ | ||
### v1.1.1 | ||
- [BREAKING (sorry, but it is 5 minutes later)]: data sources appear by constructor name on context | ||
### v1.1.0 | ||
@@ -2,0 +6,0 @@ |
@@ -32,4 +32,4 @@ 'use strict'; | ||
for (const override of dataSourceOverrides) { | ||
debug(`overriding datasource ${override.name}`); | ||
dataSources[override.name] = intercept(override, context); | ||
debug(`overriding datasource ${override.constructor.name}`); | ||
dataSources[override.constructor.name] = intercept(override, context); | ||
} | ||
@@ -39,4 +39,5 @@ | ||
for (const dataSource of component.dataSources) { | ||
if (!dataSources[dataSource.name]) { | ||
dataSources[dataSource.name] = intercept(dataSource, context); | ||
const name = dataSource.constructor.name; | ||
if (!dataSources[name]) { | ||
dataSources[name] = intercept(dataSource, context); | ||
} | ||
@@ -43,0 +44,0 @@ } |
@@ -32,13 +32,2 @@ 'use strict'; | ||
for (const dataSource of dataSources) { | ||
if (!dataSource.name) { | ||
throw new Error(`dataSource ${dataSource.constructor.name} must have a name field`); | ||
} | ||
} | ||
for (const override of dataSourceOverrides) { | ||
if (!override.name) { | ||
throw new Error(`dataSource ${override.constructor.name} must have a name field`); | ||
} | ||
} | ||
//This is really only used for avoiding directive collisions | ||
@@ -45,0 +34,0 @@ this._id = cuid().slice(12); |
{ | ||
"name": "graphql-component", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Build graphql schema with components", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -142,5 +142,2 @@ [![Build Status](https://dev.azure.com/tlivings0149/Trevor%20Livingston/_apis/build/status/tlivings.graphql-component?branchName=master)](https://dev.azure.com/tlivings0149/Trevor%20Livingston/_build/latest?definitionId=1&branchName=master) | ||
class PropertyDataSource { | ||
get name() { | ||
return 'PropertyDataSource'; | ||
} | ||
async getPropertyById(context, id) { | ||
@@ -173,2 +170,29 @@ //do some work... | ||
### Override data sources | ||
Since data sources are added to the context based on the constructor name, it is possible to simply override data sources by passing the same class name or overriding the constructor name: | ||
```javascript | ||
const { schema, context } = new GraphQLComponent({ | ||
imports: [ | ||
{ | ||
component: new Property(), | ||
exclude: ['Mutation.*'] | ||
}, | ||
{ | ||
component: new Reviews(), | ||
exclude: ['Mutation.*'] | ||
} | ||
], | ||
dataSourceOverrides: [ | ||
new class PropertyMock { | ||
static get name() { | ||
return 'PropertyDataSource'; | ||
} | ||
//...etc | ||
} | ||
] | ||
}); | ||
``` | ||
### Directly executing components | ||
@@ -175,0 +199,0 @@ |
25679
278
427