Skip to content

Commit

Permalink
Fixes made by lint-fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcohen75 committed Aug 21, 2019
1 parent 2ff7a8f commit c409925
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
51 changes: 30 additions & 21 deletions packages/apollo-gateway/src/__tests__/gateway/buildService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,24 @@ function createSdlData(sdl: string): object {
return {
data: {
_service: {
sdl: sdl
}
}
sdl: sdl,
},
},
};
}

it('makes enhanced introspection request using datasource', async () => {
fetch.mockJSONResponseOnce(createSdlData( 'extend type Query { one: String }'));
fetch.mockJSONResponseOnce(
createSdlData('extend type Query { one: String }'),
);

const gateway = new ApolloGateway({
serviceList: [{
name: 'one',
url: 'https://api.example.com/one'
}],
serviceList: [
{
name: 'one',
url: 'https://api.example.com/one',
},
],
buildService: service => {
return new RemoteGraphQLDataSource({
url: 'https://api.example.com/override',
Expand All @@ -123,21 +127,26 @@ it('makes enhanced introspection request using datasource', async () => {
});

it('customizes request on a per-service basis', async () => {
fetch.mockJSONResponseOnce(createSdlData( 'extend type Query { one: String }'))
.mockJSONResponseOnce(createSdlData('extend type Query { two: String }'))
.mockJSONResponseOnce(createSdlData('extend type Query { three: String }'));
fetch
.mockJSONResponseOnce(createSdlData('extend type Query { one: String }'))
.mockJSONResponseOnce(createSdlData('extend type Query { two: String }'))
.mockJSONResponseOnce(createSdlData('extend type Query { three: String }'));

const gateway = new ApolloGateway({
serviceList: [{
name: 'one',
url: 'https://api.example.com/one'
}, {
name: 'two',
url: 'https://api.example.com/two'
}, {
name: 'three',
url: 'https://api.example.com/three'
}],
serviceList: [
{
name: 'one',
url: 'https://api.example.com/one',
},
{
name: 'two',
url: 'https://api.example.com/two',
},
{
name: 'three',
url: 'https://api.example.com/three',
},
],
buildService: service => {
return new RemoteGraphQLDataSource({
url: service.url,
Expand Down
12 changes: 4 additions & 8 deletions packages/apollo-gateway/src/loadServicesFromRemoteEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export async function getServiceDefinitionsFromRemoteEndpoint({
headers = {},
}: {
serviceList: {
name: string,
url?: string,
name: string;
url?: string;
dataSource: GraphQLDataSource;
}[];
headers?: HeadersInit;
Expand All @@ -28,9 +28,7 @@ export async function getServiceDefinitionsFromRemoteEndpoint({
const services: ServiceDefinition[] = (await Promise.all(
serviceList.map(({ name, url, dataSource }) => {
if (!url) {
throw new Error(
`Tried to load schema from ${name} but no url found`,
);
throw new Error(`Tried to load schema from ${name} but no url found`);
}

const request: GraphQLRequest = {
Expand All @@ -47,9 +45,7 @@ export async function getServiceDefinitionsFromRemoteEndpoint({
.then(({ data, errors }) => {
if (data && !errors) {
const typeDefs = data._service.sdl as string;
const previousDefinition = serviceDefinitionMap.get(
name,
);
const previousDefinition = serviceDefinitionMap.get(name);
// this lets us know if any downstream service has changed
// and we need to recalculate the schema
if (previousDefinition !== typeDefs) {
Expand Down

0 comments on commit c409925

Please sign in to comment.