This repository has been archived on 2023-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
ARCHIVED-graphql/src/fetch-schema.js
2023-08-22 11:05:15 +02:00

34 lines
894 B
JavaScript

const axios = require('axios');
const fs = require('fs');
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../.env.local') });
async function fetchSchema() {
// Define the Directus server URL and credentials
const serverUrl = 'https://directus.andert.me';
const credentials = {
email: 'samuel@andert.me',
password: process.env.DIRECTUS_PW
};
// Login to the Directus server and get the access token
const { data: { data: { token } } } = await axios.post(`${serverUrl}/auth/login`, credentials);
// Fetch the GraphQL SDL schema
const { data: schema } = await axios.get(`${serverUrl}/server/specs/graphql`, {
headers: {
'Authorization': `Bearer ${process.env.DIRECTUS_API}`
}
});
// Save the schema to a file
fs.writeFileSync('./schemas/directus.graphql', schema);
}
fetchSchema().catch(console.error);