Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add types for object in graphiql configuration #907

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,40 @@ export interface MercuriusSchemaOptions {
schemaTransforms?: ((originalSchema: GraphQLSchema) => GraphQLSchema) | Array<(originalSchema: GraphQLSchema) => GraphQLSchema>;
}

export interface MercuriusGraphiQLOptions {
/**
* Expose the graphiql app, default `true`
*/
enabled?: boolean;
/**
* The list of plugin to add to GraphiQL
*/
plugins?: Array<{
/**
* The name of the plugin, it should be the same exported in the `umd`
*/
name: string;
/**
* The props to be passed to the plugin
*/
props?: Object;
/**
* The urls of the plugin, it's downloaded at runtime. (eg. https://unpkg.com/myplugin/....)
*/
umdUrl: string;
/**
* A function name exported by the plugin to read/enrich the fetch response
*/
fetcherWrapper?: string;
}>
}

export interface MercuriusCommonOptions {
/**
* Serve GraphiQL on /graphiql if true or 'graphiql' and if routes is true
*/
graphiql?: boolean | 'graphiql';
ide?: boolean | 'graphiql';
graphiql?: boolean | 'graphiql' | MercuriusGraphiQLOptions;
ide?: boolean | 'graphiql' | MercuriusGraphiQLOptions;
/**
* The minimum number of execution a query needs to be executed before being jit'ed.
* @default 0 - disabled
Expand Down
37 changes: 37 additions & 0 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,40 @@ app.graphql.addHook('onResolution', async function (_execution, context) {
expectType<number | undefined>(context.operationsCount)
expectType<string>(context.__currentQuery)
})

// Test graphiql configuration using an object as params
app.register(mercurius, { schema, resolvers, graphiql: { plugins: [] } })

app.register(mercurius, { schema, resolvers, ide: { enabled: false } })

app.register(mercurius, {
schema,
resolvers,
graphiql: {
enabled: true,
plugins: [
{
fetcherWrapper: 'testFetchWrapper',
umdUrl: 'http://some-url',
props: { foo: 'bar' },
name: 'pluginName'
}
]
}
})

expectError(() => {
app.register(mercurius, {
schema,
resolvers,
graphiql: {
enabled: true,
plugins: [
{
fetcherWrapper: 'testFetchWrapper',
props: { foo: 'bar' }
}
]
}
})
})