Skip to content

Commit fdf8d16

Browse files
committed
feat(graphiql): add shared types, constants, and validation
Adds type definitions, configuration validation with XSS prevention, and default GraphQL query constants. - Add GraphiQL config type definitions - Add default welcome message and shop query constants - Add config validation with security checks (313 lines of tests) - Prevent XSS attacks through URL validation and string sanitization All validation tests pass
1 parent 16966e2 commit fdf8d16

File tree

6 files changed

+549
-0
lines changed

6 files changed

+549
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Determine control key based on platform (browser-based detection)
2+
const isMac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.userAgent)
3+
const controlKey = isMac ? '⌘' : 'Ctrl'
4+
5+
export const WELCOME_MESSAGE = `# Welcome to GraphiQL for the Shopify Admin API! If you've used
6+
# GraphiQL before, you can jump to the next tab.
7+
#
8+
# GraphiQL is an in-browser tool for writing, validating, and
9+
# testing GraphQL queries.
10+
#
11+
# Type queries into this side of the screen, and you will see intelligent
12+
# typeaheads aware of the current GraphQL type schema and live syntax and
13+
# validation errors highlighted within the text.
14+
#
15+
# GraphQL queries typically start with a "{" character. Lines that start
16+
# with a # are ignored.
17+
#
18+
# Keyboard shortcuts:
19+
#
20+
# Prettify query: Shift-${controlKey}-P (or press the prettify button)
21+
#
22+
# Merge fragments: Shift-${controlKey}-M (or press the merge button)
23+
#
24+
# Run Query: ${controlKey}-Enter (or press the play button)
25+
#
26+
# Auto Complete: ${controlKey}-Space (or just start typing)
27+
#
28+
`
29+
30+
export const DEFAULT_SHOP_QUERY = `query shopInfo {
31+
shop {
32+
name
33+
url
34+
myshopifyDomain
35+
plan {
36+
displayName
37+
partnerDevelopment
38+
shopifyPlus
39+
}
40+
}
41+
}`
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export interface GraphiQLConfig {
2+
// Initial server data
3+
apiVersion: string
4+
apiVersions: string[]
5+
appName: string
6+
appUrl: string
7+
storeFqdn: string
8+
// Optional auth key
9+
key?: string
10+
11+
// API endpoints
12+
baseUrl: string
13+
14+
// Optional initial query state
15+
query?: string
16+
variables?: string
17+
18+
// Default queries for tabs
19+
defaultQueries?: {
20+
query: string
21+
variables?: string
22+
preface?: string
23+
}[]
24+
}
25+
26+
// Global config interface
27+
declare global {
28+
interface Window {
29+
__GRAPHIQL_CONFIG__?: GraphiQLConfig
30+
}
31+
}
32+
33+
export {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './config.ts'
2+
export * from './serverStatus.ts'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface ServerStatus {
2+
serverIsLive: boolean
3+
appIsInstalled: boolean
4+
storeFqdn?: string
5+
appName?: string
6+
appUrl?: string
7+
}

0 commit comments

Comments
 (0)