Skip to content

Commit

Permalink
feat: add types for object in graphiql configuration (#907)
Browse files Browse the repository at this point in the history
* feat: add types for object in graphiql configuration

* feat: add test to types
  • Loading branch information
codeflyer committed Nov 2, 2022
1 parent 780c668 commit b4d70fc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
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' }
}
]
}
})
})

0 comments on commit b4d70fc

Please sign in to comment.