Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2624,6 +2624,10 @@ class Extractor {
return this.report(node, E.ambiguousNumberType());
} else if (ts.isTypeLiteralNode(node)) {
return this.report(node, E.unsupportedTypeLiteral());
} else if (ts.isTypeOperatorNode(node)) {
if (node.operator === ts.SyntaxKind.ReadonlyKeyword) {
return this.collectType(node.type, ctx);
}
}
// TODO: Better error message. This is okay if it's a type reference, but everything else is not.
this.reportUnhandled(node, "type", E.unknownGraphQLType());
Expand Down
7 changes: 7 additions & 0 deletions src/tests/fixtures/arguments/ReadonlyArrayOfString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @gqlType */
export default class SomeType {
/** @gqlField */
hello(greetings: readonly string[]): string {
return `${greetings.join(", ")} world!`;
}
}
53 changes: 53 additions & 0 deletions src/tests/fixtures/arguments/ReadonlyArrayOfString.ts.expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# arguments/ReadonlyArrayOfString.ts

## Input

```ts title="arguments/ReadonlyArrayOfString.ts"
/** @gqlType */
export default class SomeType {
/** @gqlField */
hello(greetings: readonly string[]): string {
return `${greetings.join(", ")} world!`;
}
}
```

## Output

### SDL

```graphql
type SomeType {
hello(greetings: [String!]!): String
}
```

### TypeScript

```ts
import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLList } from "graphql";
export function getSchema(): GraphQLSchema {
const SomeTypeType: GraphQLObjectType = new GraphQLObjectType({
name: "SomeType",
fields() {
return {
hello: {
name: "hello",
type: GraphQLString,
args: {
greetings: {
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString)))
}
},
resolve(source, args) {
return source.hello(args.greetings);
}
}
};
}
});
return new GraphQLSchema({
types: [SomeTypeType]
});
}
```
1 change: 1 addition & 0 deletions website/docs/07-changelog/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- **Features**
- Added support for async derived context functions. Derived context functions can now return `Promise<T>` and Grats will automatically generate the necessary `await` expressions in resolver code.
- Added support for `readonly T[]` as parsable GraphQL types.

Changes in this section are not yet released. If you need access to these changes before we cut a release, check out our `@main` NPM releases. Each commit on the main branch is [published to NPM](https://www.npmjs.com/package/grats?activeTab=versions) under the `main` tag.

Expand Down