-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
39 lines (35 loc) · 851 Bytes
/
Copy pathtest.js
File metadata and controls
39 lines (35 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// fetch-graphql-jobs.mjs (ESM) or .js in Node 18+
const query = `
query {
jobs(first: 5) {
id
title
description
remote
company { name logoUrl }
tags { name }
}
}
`;
async function fetchJobs() {
try {
const response = await fetch('https://api.graphql.jobs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query })
});
if (!response.ok) {
const text = await response.text();
throw new Error(`HTTP ${response.status}: ${text}`);
}
const { data, errors } = await response.json();
if (errors && errors.length) {
console.error('GraphQL errors:', errors);
return;
}
console.log('Jobs:', data?.jobs ?? []);
} catch (error) {
console.error('Fetch error:', error);
}
}
fetchJobs();