Skip to content

Commit

Permalink
added package-lock to gitignore, some cleanup in code and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tlivings committed Jan 27, 2022
1 parent 3ae43bd commit 1cf0b27
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ Thumbs.db
.Spotlight-V100
.Trashes
*.swp

# Package lock
package-lock.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Generally speaking, each instance of `GraphQLComponent` has reference to an inst
* when a `GraphQLComponent` instance has `imports` (ie. other `GraphQLComponent` instances or component configuration objects) [graphql-tools stitchSchemas()](https://www.graphql-tools.com/docs/schema-stitching/) is used to create a "gateway" or aggregate schema that is the combination of the underlying imported schemas, and the typeDefs/resolvers passed to the root or importing `GraphQLComponent`
* when a `GraphQLComponent` has no imports, graphql-tools' `makeExecuteableSchema({typeDefs, resolvers})` is used to generate an executable GraphQL schema using the passed/required inputs.

It's worth noting that `GraphQLComponent` can also be used to construct componentized Apollo Federated schemas. That is, if you pass the `federation: true` flag to a GraphQLComponent constructor, `@apollo/federation`'s [buildFederatedSchema()]() is used in lieu of graphql-tools `makeExecutableSchema({...})` and the above still schema construction rule applies. The general use case here might be to help modularize an individual federated subschema service implementation.
It's worth noting that `GraphQLComponent` can also be used to construct componentized Apollo Federated schemas. That is, if you pass the `federation: true` flag to a GraphQLComponent constructor, `@apollo/federation`'s [buildSubgraphSchema()](https://www.apollographql.com/docs/federation/api/apollo-subgraph/) is used in lieu of graphql-tools `makeExecutableSchema({...})` and the above still schema construction rule applies. The general use case here might be to help modularize an individual federated subschema service implementation.

### Running the examples

Expand Down
4 changes: 2 additions & 2 deletions examples/federation/property-service/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const resolvers = {
}
},
Property: {
__resolveReference(ref, context) {
return context.dataSources.PropertyDataSource.getPropertyById(ref.id);
__resolveReference(ref, { dataSources }) {
return dataSources.PropertyDataSource.getPropertyById(ref.id);
}
}
};
Expand Down
22 changes: 14 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,25 @@ class GraphQLComponent {

return delegateToSchema(options);
}


_getMakeSchemaFunction() {
if (this._federation) {
return this.makeFederatedSchemaWithDirectives;
return (schemaConfig) => {
const schema = buildFederatedSchema(schemaConfig);

// allows a federated schema to have custom directives using the old class based directive implementation
if (this._directives) {
SchemaDirectiveVisitor.visitSchemaDirectives(schema, this._directives);
}

return schema;
};
}
else if (this._makeExecutableSchema) {
if (this._makeExecutableSchema) {
return this._makeExecutableSchema
}

return defaultMakeExecutableSchema;
}

Expand Down Expand Up @@ -141,12 +152,7 @@ class GraphQLComponent {

const makeSchema = this._getMakeSchemaFunction();

this._schema = this._federation ? buildFederatedSchema([schemaConfig]) : makeSchema(schemaConfig);

// allows a federated schema to have custom directives using the old class based directive implementation
if (this._federation && this._directives) {
SchemaDirectiveVisitor.visitSchemaDirectives(this._schema, this._directives);
}
this._schema = makeSchema(schemaConfig);
}

if (this._mocks !== undefined && typeof this._mocks === 'boolean' && this._mocks === true) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"repository": "https://github.com/ExpediaGroup/graphql-component",
"license": "MIT",
"dependencies": {
"@apollo/federation": "^0.25.1",
"@apollo/federation": "^0.28.0",
"debug": "^4.3.1",
"graphql-tools": "^7.0.5"
},
Expand Down

0 comments on commit 1cf0b27

Please sign in to comment.