Skip to content

Commit f945573

Browse files
committed
Started work on introspection
1 parent 252abf1 commit f945573

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/type/__tests__/introspection-test.ts

+58
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('Introspection', () => {
2626
descriptions: false,
2727
specifiedByUrl: true,
2828
directiveIsRepeatable: true,
29+
errorBehavior: true,
2930
});
3031

3132
const result = graphqlSync({ schema, source });
@@ -35,6 +36,7 @@ describe('Introspection', () => {
3536
queryType: { name: 'SomeObject', kind: 'OBJECT' },
3637
mutationType: null,
3738
subscriptionType: null,
39+
defaultErrorBehavior: 'PROPAGATE',
3840
types: [
3941
{
4042
kind: 'OBJECT',
@@ -1754,4 +1756,60 @@ describe('Introspection', () => {
17541756
});
17551757
expect(result).to.not.have.property('errors');
17561758
});
1759+
1760+
it('reflects the default error behavior (default)', () => {
1761+
const schema = buildSchema(`
1762+
type SomeObject {
1763+
someField: String
1764+
}
1765+
1766+
schema {
1767+
query: SomeObject
1768+
}
1769+
`);
1770+
1771+
const source = getIntrospectionQuery({
1772+
descriptions: false,
1773+
specifiedByUrl: true,
1774+
directiveIsRepeatable: true,
1775+
});
1776+
1777+
const result = graphqlSync({ schema, source });
1778+
expect(result).to.deep.equal({
1779+
data: {
1780+
__schema: {
1781+
defaultErrorBehavior: 'PROPAGATE',
1782+
},
1783+
},
1784+
});
1785+
});
1786+
1787+
it('reflects the default error behavior (NO_PROPAGATE)', () => {
1788+
const schema = buildSchema(`
1789+
type SomeObject {
1790+
someField: String
1791+
}
1792+
1793+
schema @behavior(onError: NO_PROPAGATE) {
1794+
query: SomeObject
1795+
}
1796+
`);
1797+
1798+
const source = /* GraphQL */ `
1799+
{
1800+
__schema {
1801+
defaultErrorBehavior
1802+
}
1803+
}
1804+
`;
1805+
1806+
const result = graphqlSync({ schema, source });
1807+
expect(result).to.deep.equal({
1808+
data: {
1809+
__schema: {
1810+
defaultErrorBehavior: 'NO_PROPAGATE',
1811+
},
1812+
},
1813+
});
1814+
});
17571815
});

src/utilities/getIntrospectionQuery.ts

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export interface IntrospectionOptions {
3838
* Default: false
3939
*/
4040
oneOf?: boolean;
41+
42+
/**
43+
* Whether target GraphQL server supports changing error behaviors.
44+
* Default: false
45+
*/
46+
errorBehavior?: boolean;
4147
}
4248

4349
/**
@@ -52,6 +58,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
5258
schemaDescription: false,
5359
inputValueDeprecation: false,
5460
oneOf: false,
61+
errorBehavior: false,
5562
...options,
5663
};
5764

@@ -65,6 +72,9 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
6572
const schemaDescription = optionsWithDefault.schemaDescription
6673
? descriptions
6774
: '';
75+
const defaultErrorBehavior = optionsWithDefault.errorBehavior
76+
? 'defaultErrorBehavior'
77+
: '';
6878

6979
function inputDeprecation(str: string) {
7080
return optionsWithDefault.inputValueDeprecation ? str : '';
@@ -78,6 +88,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
7888
queryType { name kind }
7989
mutationType { name kind }
8090
subscriptionType { name kind }
91+
${defaultErrorBehavior}
8192
types {
8293
...FullType
8394
}

0 commit comments

Comments
 (0)