Initial Wundergraph Setup

This commit is contained in:
Samuel Andert
2023-08-25 09:45:46 +02:00
commit 842cd376cc
33 changed files with 9654 additions and 0 deletions

View File

@ -0,0 +1,6 @@
query Continents {
countries_continents {
name
code
}
}

View File

@ -0,0 +1,7 @@
query Countries($filter: countries_CountryFilterInput) {
countries_countries(filter: $filter) {
code
name
capital
}
}

View File

@ -0,0 +1,6 @@
query Dragons {
spacex_dragons {
name
active
}
}

View File

@ -0,0 +1,6 @@
query Projects {
directus_projects {
id
text
}
}

View File

@ -0,0 +1,6 @@
query Projects {
directus_todos {
id
task
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,30 @@
import axios from 'axios';
import fs from 'fs';
import dotenv from 'dotenv';
dotenv.config();
export async function fetchSchemas() {
// Define the Directus server URL and credentials
const serverUrl = 'https://directus.andert.me';
const credentials = {
email: process.env.EMAIL,
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('./.wundergraph/schemas/directus.graphql', schema);
}
fetchSchemas().catch(console.error);

View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
}
}

View File

@ -0,0 +1,55 @@
import { configureWunderGraphApplication, cors, EnvironmentVariable, introspect, templates } from '@wundergraph/sdk';
import server from './wundergraph.server';
import operations from './wundergraph.operations';
import fs from 'fs';
import path from 'path';
const directusSchema = fs.readFileSync(path.join(path.resolve(), './schemas/directus.graphql'), 'utf8');
const countries = introspect.graphql({
apiNamespace: 'countries',
url: 'https://countries.trevorblades.com/',
});
const spaceX = introspect.graphql({
apiNamespace: 'spacex',
url: 'https://spacex-api.fly.dev/graphql/',
});
const directus = introspect.graphql({
apiNamespace: 'directus',
loadSchemaFromString: directusSchema,
url: 'https://directus.andert.me/graphql',
headers: (builder) => builder.addStaticHeader('Authorization', 'Bearer Bv5RknRvv5AZouxcYdBJgVOe3ZC493Y3')
});
// configureWunderGraph emits the configuration
configureWunderGraphApplication({
apis: [countries, spaceX, directus],
server,
operations,
generate: {
codeGenerators: [
{
templates: [
// use all the typescript react templates to generate a client
...templates.typescript.all,
],
path: '../src/lib/.wundergraph/generated',
},
],
},
cors: {
...cors.allowAll,
allowedOrigins:
process.env.NODE_ENV === 'production'
? [
// change this before deploying to production to the actual domain where you're deploying your app
'http://localhost:3000',
]
: ['http://localhost:3000', new EnvironmentVariable('WG_ALLOWED_ORIGIN')],
},
security: {
enableGraphQLEndpoint: process.env.NODE_ENV !== 'production' || process.env.GITPOD_WORKSPACE_ID !== undefined,
},
});

View File

@ -0,0 +1,32 @@
import { configureWunderGraphOperations } from '@wundergraph/sdk';
import type { OperationsConfiguration } from '../src/lib/.wundergraph/generated/wundergraph.operations';
export default configureWunderGraphOperations<OperationsConfiguration>({
operations: {
defaultConfig: {
authentication: {
required: false,
},
},
queries: (config) => ({
...config,
caching: {
enable: false,
staleWhileRevalidate: 60,
maxAge: 60,
public: true,
},
liveQuery: {
enable: true,
pollingIntervalSeconds: 1,
},
}),
mutations: (config) => ({
...config,
}),
subscriptions: (config) => ({
...config,
}),
custom: {},
},
});

View File

@ -0,0 +1,11 @@
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql';
import { configureWunderGraphServer } from '@wundergraph/sdk/server';
import type { HooksConfig } from '../src/lib/.wundergraph/generated/wundergraph.hooks';
import type { InternalClient } from '../src/lib/.wundergraph/generated/wundergraph.internal.client';
export default configureWunderGraphServer(() => ({
hooks: {
queries: {},
mutations: {},
},
}));