Skip to content

Commit

Permalink
Added introspection query for older GraphQL servers.
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Mar 27, 2018
1 parent b65b0e4 commit 72ccce3
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/services/gql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'rxjs/Rx';
// TODO - Check if this is necessary
import 'rxjs/add/observable/throw';

import { oldIntrospectionQuery } from './oldIntrospectionQuery';

@Injectable()
export class GqlService {
defaultHeaders = {
Expand Down Expand Up @@ -118,7 +120,17 @@ export class GqlService {
return this.send(introspectionQuery).map(data => {
console.log('introspection', data.data);
return data.data;
}).do(() => this.api_url = currentApiUrl);
})
.catch((err) => {
console.log('Error from first introspection query.', err);

// Try the old introspection query
return this.send(oldIntrospectionQuery).map(data => {

This comment has been minimized.

Copy link
@lon-io

lon-io Mar 27, 2018

Collaborator

Nice, but is there a way to handle a visual indication, maybe a flash message?

This comment has been minimized.

Copy link
@imolorhe

imolorhe Mar 27, 2018

Author Collaborator

That could be a nice-to-have.

console.log('old introspection', data.data);
return data.data;
});
})
.do(() => this.api_url = currentApiUrl);
}

getIntrospectionData() {
Expand Down
80 changes: 80 additions & 0 deletions src/app/services/oldIntrospectionQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
export const oldIntrospectionQuery = `
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
args {
...InputValue
}
onOperation
onFragment
onField
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
`;

0 comments on commit 72ccce3

Please sign in to comment.