cdklabs / cdklabs/awscdk-appsync-utils

Support for typing definition keys

Open
#529 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
26
Forks
6
Avg merge
9m
Merged PRs (30d)
4

Description

Staying in line with using type safety, it would be great if typing support was built into the library by default for the type definition keys. Take a look at the following:
```typescript
type DefinitionType = {
[K in keyof T]: IField;
};

interface TypedIntermediateTypeOptions extends IntermediateTypeOptions {
readonly definition: DefinitionType;
}
class ExtendedInterfaceType extends InterfaceType {
constructor(name: string, options: TypedIntermediateTypeOptions) {
super(name, options);
}
}

export interface DataItem {
day: number;
month: number;
source: DataProvider;
timestamp: number;
year: number;
}

// will give an error since source is missing
export const DataItemType = new ExtendedInterfaceType("DataItem", {
definition: {
timestamp: GraphqlType.int(),
year: GraphqlType.int(),
month: GraphqlType.int(),
day: GraphqlType.int(),
},
});

// will not give an error since all properties are implemented
export const DataItemType = new ExtendedInterfaceType("DataItem", {
definition: {
timestamp: GraphqlType.int(),
year: GraphqlType.int(),
month: GraphqlType.int(),
day: GraphqlType.int(),
source: DataProviderEnumType.attribute(),
},
});
```

We've made the choice to make the type required on the interface, ensuring consistent typing everywhere, but for this particular library it probably makes more sense to make it optional (will also ensure it isn't a breaking change).

I don't think the implementation would be a heavy lift, and am happy to submit a PR whenever I get a chance, but what do you all think about this functionality? Agree it makes sense to build it into the library?

Contributor guide

Open the contributing guide

Research direction

Search the repository for InterfaceType, IntermediateTypeOptions, and IField, then trace how the definition option is typed and consumed. Compare the current type definitions with the TypedIntermediateTypeOptions example in the issue. Done means type-definition keys can be checked consistently without forcing a breaking change for existing callers.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.