question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript Type definition for Graphql-playground-html mismatching

See original GitHub issue

I am running into an issue with TS type definitions for graphql-playground-html. I have checked that all my Apollo npm packages are up to date to the latest 2.6.2 version.

Intended outcome:

I want to specify settings in for Playground as described by the Apollo doc.

Specifically, I want to define configs related to schema.polling

I have my settings like this, which is taken from the Graphql-playground doc. It’s also what I see when I open my iGraphql playground’s Settings.

playground: {
    settings: {
      "editor.cursorShape": "line" as CursorShape,
      "editor.fontFamily": "'Source Code Pro', 'Consolas', 'Inconsolata', 'Droid Sans Mono', 'Monaco', monospace",
      "editor.fontSize": 14,
      "editor.reuseHeaders": true,
      "editor.theme": "dark" as Theme,
      "general.betaUpdates": false,
      "prettier.printWidth": 80,
      "prettier.tabWidth": 2,
      "prettier.useTabs": false,
      "request.credentials": "omit",
      "schema.disableComments": true,
      "schema.polling.enable": false,
      "schema.polling.endpointFilter": "*localhost*",
      "schema.polling.interval": 2000,
      "tracing.hideTracingResponse": true,
      "queryPlan.hideQueryPlanResponse": true
    },
...

I expected my app to compile and take in the new settings every time I start my dev server.

Actual outcome:

However, when I compile my app, I get a TS error:

Object literal may only specify known properties, and ''schema.disableComments'' does not exist in type 'ISettings'.

I then looked at the actual type definition imported with apollo-server from @apollographql/graphql-playground-html/dist/render-playground-page

and I see the actual definition ISettings is missing more fields as compared to Graphql-playground’s settings interface:

export interface ISettings {
    'general.betaUpdates': boolean;
    'editor.cursorShape': CursorShape;
    'editor.theme': Theme;
    'editor.reuseHeaders': boolean;
    'tracing.hideTracingResponse': boolean;
    'queryPlan.hideQueryPlanResponse'?: boolean;
    'editor.fontSize': number;
    'editor.fontFamily': string;
    'request.credentials': string;
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
South-Pawcommented, Jun 3, 2020

Unsure why this is closed - the types are certainly still out of sync with the playground…

image

1reaction
Elyx0commented, Jul 29, 2019
const myServer = new ApolloServer({
  playground: {
    settings: {
      'editor.theme': 'light' as Theme,
      'schema.polling.interval': 20000,
    },
  },
});

Is enough to make TS complain:

Screen Shot 2019-07-29 at 4 28 09 PM
Types of property 'settings' are incompatible.
  Type '{ 'editor.theme': Theme; 'schema.polling.interval': number; }' is not assignable to type 'RecursivePartial<ISettings>'.
    Object literal may only specify known properties, and ''schema.polling.interval'' does not exist in type 'RecursivePartial<ISettings>'.ts(2326)
types.d.ts(62, 5): The expected type comes from property 'playground' which is declared here on type 'Config'

Edit: casting as Config as any solved it for now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript and GraphQL mismatch types between ...
It looks like there is a type mismatch between Event and IEvent . Can't say much without seeing the definition of Event ....
Read more >
Integrate TypeScript with GraphQL using TypeGraphQL
Build an API to integrate TypeScript with GraphQL using the TypeGraphQL library, which simplifies creating GraphQL APIs in Node.js.
Read more >
How to Use TypeScript with GraphQL using TypeGraphQL
In this tutorial, I'll explain what TypeScript and GraphQL are, and the benefits of using them. Then I'll show you how you can...
Read more >
API Reference: ApolloServer - Apollo GraphQL Docs
This article documents the ApolloServer class from the @apollo/server package. ... from talking to it directly, like Apollo Sandbox and GraphQL Playground.
Read more >
How to Generate TypeScript Type Definitions and Code ...
Using GraphQL with TypeScript has great benefits because you can use the GraphQL schema to create TypeScript type definitions and code to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found