···
let url: URL | undefined;
36
-
let config: undefined | SchemaOrigin;
34
+
let config: { headers: Record<string, unknown> } | undefined;
if (typeof schema === 'object') {
url = new URL(schema.url);
39
+
config = { headers: schema.headers };
47
-
logger(`Fetching introspection from ${url.toString()}`);
48
-
fetch(url.toString(), {
46
+
const pollSchema = () => {
47
+
logger(`Fetching introspection from ${url!.toString()}`);
48
+
fetch(url!.toString(), {
...(config.headers || {}),
'Content-Type': 'application/json',
···
'Content-Type': 'application/json',
59
-
body: JSON.stringify({
60
-
query: getIntrospectionQuery({
62
-
schemaDescription: false,
63
-
inputValueDeprecation: false,
64
-
directiveIsRepeatable: false,
65
-
specifiedByUrl: false,
58
+
body: JSON.stringify({
59
+
query: getIntrospectionQuery({
61
+
schemaDescription: false,
62
+
inputValueDeprecation: false,
63
+
directiveIsRepeatable: false,
64
+
specifiedByUrl: false,
70
-
logger(`Got response ${response.statusText} ${response.status}`);
71
-
if (response.ok) return response.json();
72
-
else return response.text();
75
-
logger(`Got result ${JSON.stringify(result)}`);
76
-
if (typeof result === 'string') {
77
-
logger(`Got error while fetching introspection ${result}`);
78
-
} else if (result.data) {
80
-
ref.current = buildClientSchema(
81
-
(result as { data: IntrospectionQuery }).data
83
-
ref.version = ref.version + 1;
84
-
logger(`Got schema for ${url!.toString()}`);
69
+
logger(`Got response ${response.statusText} ${response.status}`);
70
+
if (response.ok) return response.json();
71
+
else return response.text();
74
+
logger(`Got result ${JSON.stringify(result)}`);
75
+
if (typeof result === 'string') {
76
+
logger(`Got error while fetching introspection ${result}`);
77
+
} else if (result.data) {
79
+
ref.current = buildClientSchema(
80
+
(result as { data: IntrospectionQuery }).data
93
-
logger(`Got schema error for ${e.message}`);
82
+
ref.version = ref.version + 1;
83
+
logger(`Got schema for ${url!.toString()}`);
92
+
logger(`Got schema error for ${e.message}`);
95
+
logger(`Got invalid response ${JSON.stringify(result)}`);
96
-
logger(`Got invalid response ${JSON.stringify(result)}`);
101
+
setInterval(() => {
} else if (typeof schema === 'string') {
const isJson = schema.endsWith('json');
const resolvedPath = path.resolve(path.dirname(root), schema);