Skip to content

Commit d17db0d

Browse files
committed
Add local GraphQL Playground for SDL development
This commit introduces a new file `test-playground.mjs`, which sets up a local GraphQL Playground server for testing static schemas. The server runs on http://localhost:4000/graphql and utilizes a static SDL schema along with stub scalars. This tool is intended for development and testing purposes only, not for production use.
1 parent fa17f5f commit d17db0d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test-playground.mjs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
Local GraphQL Playground for static schema (SDL) development/testing.
5+
- Runs a standalone server on http://localhost:4000/graphql
6+
- Uses only the static SDL (schema-static.mjs) and stub scalars
7+
- Does not use dynamic data or production API logic
8+
- Useful for viewing schema docs and testing queries against the static schema
9+
- Not used in production or deployment
10+
*/
11+
12+
import http from 'http'
13+
import { createYoga } from 'graphql-yoga'
14+
import { makeExecutableSchema } from '@graphql-tools/schema'
15+
import staticSDL from './schema-static.mjs'
16+
17+
// Stubs for custom scalars referenced in staticSDL
18+
const stubSDL = `
19+
scalar LanguageCode
20+
scalar ItemType
21+
scalar ItemCategoryName
22+
scalar HandbookCategoryName
23+
`
24+
25+
// Build schema from static SDL and stubs
26+
const schema = makeExecutableSchema({
27+
typeDefs: [staticSDL, stubSDL],
28+
resolvers: {},
29+
})
30+
31+
// Enable GraphiQL at /graphql for local exploration
32+
const yoga = createYoga({
33+
schema,
34+
graphiql: true,
35+
})
36+
37+
// Start HTTP server on port 4000
38+
const server = http.createServer(yoga)
39+
const PORT = 4000
40+
server.listen(PORT, () => {
41+
console.log(
42+
`🚀 GraphQL Playground running at http://localhost:${PORT}/graphql`
43+
)
44+
})

0 commit comments

Comments
 (0)