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.

Extend interfaces when extending schemas

See original GitHub issue

Hi!

I just realised that if you extend a schema, e.g.

const WorkspaceSchema = Joi.object({
 statistics:Joi.object({
     views: Joi.number()
     })
}).label('IWorkspace')

const ProjectSchema = WorkspaceSchema.keys({
  statistics:Joi.object({
    users:Joi.number()
    })
}).label('IProject')

You end up with two interfaces:

export interface IWorkspace {
  statistics: {
    views: number;
  };
}

and

export interface IProject {
  statistics: {
    users: number
   }
}

Wouldn’t it make more sense to extend IProject with IWorkspace?

export interface IProject extends IWorkspace {
  statistics: {
    users: number
   }
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kingmesalcommented, May 8, 2022

I have found in Joi where the data is, and modifying a test to be able to cover an implementation will be easy, because you already test concat. However, I cannot figure out where you write out the actual export interface Foo

    "metas": [
      {
        "className": "Key"
      },
      {
        "className": "Metadata"
      },
      {
        "className": "Value"
      },
      {
        "className": "CombinedRecord"
      }
    ],

it should just be able to write out export interface CombinedRecord extends Value, Metadata, Key

All the other logic is already in place for having properly created the interface. I’m just trudging through the code and have a rather difficult time interpreting where that work is being done.

1reaction
mrjono1commented, Jan 28, 2021

That would be nicer, I’m not sure if Joi exposes this type of information, but this can be investigated

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interface extends multiple interfaces in GraphQL Schema
The answer to this question when it was asked was No, it is not possible for interfaces to extend (or implement) other interfaces....
Read more >
Extending GraphQL: Part 2 - Types and Interfaces
After successfully creating a field with arguments and context, we are going to have a look at types and interfaces in GraphQL and...
Read more >
Interfaces and inheritance - TypeGraphQL
The main idea of TypeGraphQL is to create GraphQL types based on TypeScript classes. In object-oriented programming it is common to create interfaces...
Read more >
How to Extend the Schema - Win32 apps | Microsoft Learn
Determine the method of extension. Once you have carefully designed your schema changes, the next step is to decide which method to use...
Read more >
Extending generated schema types · Issue #592 - GitHub
Hi, Is it possible to use the type for specific schemas and extend them? For example... Part of a generated file interface components ......
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