Initial Wundergraph Setup
This commit is contained in:
6
.wundergraph/operations/Continents.graphql
Normal file
6
.wundergraph/operations/Continents.graphql
Normal file
@ -0,0 +1,6 @@
|
||||
query Continents {
|
||||
countries_continents {
|
||||
name
|
||||
code
|
||||
}
|
||||
}
|
7
.wundergraph/operations/Countries.graphql
Normal file
7
.wundergraph/operations/Countries.graphql
Normal file
@ -0,0 +1,7 @@
|
||||
query Countries($filter: countries_CountryFilterInput) {
|
||||
countries_countries(filter: $filter) {
|
||||
code
|
||||
name
|
||||
capital
|
||||
}
|
||||
}
|
6
.wundergraph/operations/Dragons.graphql
Normal file
6
.wundergraph/operations/Dragons.graphql
Normal file
@ -0,0 +1,6 @@
|
||||
query Dragons {
|
||||
spacex_dragons {
|
||||
name
|
||||
active
|
||||
}
|
||||
}
|
6
.wundergraph/operations/Projects.graphql
Normal file
6
.wundergraph/operations/Projects.graphql
Normal file
@ -0,0 +1,6 @@
|
||||
query Projects {
|
||||
directus_projects {
|
||||
id
|
||||
text
|
||||
}
|
||||
}
|
6
.wundergraph/operations/Todos.graphql
Normal file
6
.wundergraph/operations/Todos.graphql
Normal file
@ -0,0 +1,6 @@
|
||||
query Projects {
|
||||
directus_todos {
|
||||
id
|
||||
task
|
||||
}
|
||||
}
|
1081
.wundergraph/schemas/directus.graphql
Normal file
1081
.wundergraph/schemas/directus.graphql
Normal file
File diff suppressed because it is too large
Load Diff
30
.wundergraph/schemas/fetch-schemas.js
Normal file
30
.wundergraph/schemas/fetch-schemas.js
Normal 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);
|
17
.wundergraph/tsconfig.json
Normal file
17
.wundergraph/tsconfig.json
Normal 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
|
||||
}
|
||||
}
|
55
.wundergraph/wundergraph.config.ts
Normal file
55
.wundergraph/wundergraph.config.ts
Normal 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,
|
||||
},
|
||||
});
|
32
.wundergraph/wundergraph.operations.ts
Normal file
32
.wundergraph/wundergraph.operations.ts
Normal 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: {},
|
||||
},
|
||||
});
|
11
.wundergraph/wundergraph.server.ts
Normal file
11
.wundergraph/wundergraph.server.ts
Normal 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: {},
|
||||
},
|
||||
}));
|
Reference in New Issue
Block a user