-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Summary
Allow gql-tada to work with minimal or no schema introspection for a more progressive developer experience, providing basic structure inference even when full schema types aren't available.
Current Behavior
gql-tada requires a full introspection type to be provided. Without it, the type system errors immediately.
Proposed Enhancement
Support a "minimal schema" mode where gql-tada can still provide basic type inference without full schema introspection:
With minimal introspection (just root types + standard scalars):
type MinimalIntrospection = {
name: never
query: 'Query'
mutation: never
subscription: never
types: {
Query: { kind: 'OBJECT', name: 'Query', fields: {} }
String: { name: 'String' }
Int: { name: 'Int' }
Float: { name: 'Float' }
Boolean: { name: 'Boolean' }
ID: { name: 'ID' }
}
}
const graphql = initGraphQLTada<{ introspection: MinimalIntrospection }>()
const query = graphql(`
query {
getX {
id
name
}
}
`)
type Result = ResultOf<typeof query>
// Currently works: { getX: unknown }
// Top-level field names ARE preserved!Even better: Support NO introspection as a fallback:
// Allow this without error
const graphql = initGraphQLTada<{}>()
// Provide basic structure with all fields as `unknown`
const query = graphql(`query { user { id } }`)
// Result: { user: unknown }Benefits
Progressive Enhancement
Developers could use gql-tada in stages:
- No schema - Basic structure validation, fields are
unknown - Minimal schema - Top-level field names typed, values are
unknown - Full schema - Complete type safety
Lower Barrier to Entry
- Try gql-tada without setting up schema introspection first
- Prototype quickly with any GraphQL API
- Still get some type safety (structure validation) even without schema
Graceful Degradation
- If schema generation fails, basic types still work
- Better developer experience when working with unfamiliar APIs
- Useful for debugging/exploration
Use Cases
This might primarily be useful for:
- Prototyping - Quick experimentation with GraphQL APIs
- Learning - Lower barrier for developers new to gql-tada
- Exploration - Testing unfamiliar APIs without full schema setup
- Fallback - Graceful degradation when schema isn't available
Caveats
This is admittedly a polish/convenience feature rather than solving a critical real-world problem. Most production use cases will have proper schema introspection. However, it could make the initial developer experience more welcoming and progressive.
Related
This came up while exploring gql-tada integration for Graffle, where we want to support both:
- Generated clients with full schema types
- Raw clients without schema generation
Having minimal schema support would allow raw clients to still benefit from basic structure validation.
Curious if this aligns with gql-tada's design philosophy or if the added complexity isn't worth the convenience benefit.