Skip to content

Feature - @InterfaceType decorator#46

Merged
felipesabino merged 7 commits intomasterfrom
feature/interface-decorator
Nov 22, 2017
Merged

Feature - @InterfaceType decorator#46
felipesabino merged 7 commits intomasterfrom
feature/interface-decorator

Conversation

@felipesabino
Copy link
Copy Markdown

@felipesabino felipesabino commented Nov 13, 2017

  • Added @InterfaceType decorator - Create Interface Decorator #28
  • Inferring @ObjectType classes that implements the interface decorator but are not directly used anywhere else.
  • Added @InterfaceType to Improve documentation #23 issue description for future improvement
  • Added @InterfaceType to README

Comment thread src/array.utils.ts Outdated
@@ -0,0 +1,25 @@
/**
* Concats two arrays
* @param itemsA fist array argument
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

@felipesabino felipesabino changed the title [WIP] Feature - @Interface decorator [WIP] Feature - @InterfaceType decorator Nov 20, 2017
@felipesabino felipesabino force-pushed the feature/interface-decorator branch from 5bc522e to 319390b Compare November 20, 2017 13:05
@felipesabino felipesabino changed the title [WIP] Feature - @InterfaceType decorator Feature - @InterfaceType decorator Nov 20, 2017
Copy link
Copy Markdown

@thiago-soliveira thiago-soliveira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Comment thread src/array.utils.ts
} else {
return items;
}
}, collection);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about lodash.flatten and lodash.concat?

Copy link
Copy Markdown
Author

@felipesabino felipesabino Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thiago-soliveira Thought about that but I prefer avoid adding extra dependencies for very simple use cases whenever possible

export function interfaceTypeFactory(target: any): graphql.GraphQLInterfaceType | undefined {
return getMetadataBuilder().buildInterfaceTypeMetadata(target)
.map(metadata => {
if (interfaceTypeCache[metadata.name]) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum... what about:

if (!interfaceTypeCache[metadata.name]) {
  interfaceTypeCache[metadata.name] = new ...
}

return interfaceTypeCache[metadata.name];

Comment thread src/type-factory/object.type-factory.ts Outdated
const fieldMetadataList: { target: Function, field: FieldMetadata}[] = getMetadataBuilder()
.buildFieldMetadata(target.prototype)
.map(field => ({
target: target,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible shorthand:

({ target, field })

name: arg.name,
description: arg.description,
isInput: arg.isInput,
interfaces: Array.prototype.concat.apply([], arg.interfaces.map(this.buildInterfaceTypeMetadata)),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use flatmap here

@felipesabino felipesabino force-pushed the feature/interface-decorator branch from ffae888 to 0b2bbcf Compare November 22, 2017 21:44
@felipesabino felipesabino merged commit 223937c into master Nov 22, 2017
@felipesabino felipesabino deleted the feature/interface-decorator branch November 22, 2017 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants