Skip to content

Commit

Permalink
trying stuff with custom scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
remorses committed Jan 15, 2024
1 parent 81a39be commit 982dcd3
Show file tree
Hide file tree
Showing 10 changed files with 1,852 additions and 728 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
For new changes see the new changelog built with [Notaku](https://notaku.so) and Notion: https://changelog.genql.dev

## 2.11

- Fix custom scalars typed with object types
- Make required top level arguments with defaults non required

## 2.10.0

Fixed problem generating interfaces without any implementation
Expand Down
2 changes: 1 addition & 1 deletion beskar
Submodule beskar updated 1 files
+1 −1 package.json
1 change: 1 addition & 0 deletions integration-tests/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type RecursiveType {
type Repository {
createdAt: String!
forks(filter: String): ForkConnection
scalarButWithRequiredArgs(x: Int!): String!
customScalar: MyCustomScalar
}

Expand Down
2 changes: 2 additions & 0 deletions integration-tests/generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface RecursiveType {
export interface Repository {
createdAt: Scalars['String']
forks: (ForkConnection | null)
scalarButWithRequiredArgs: Scalars['String']
customScalar: (Scalars['MyCustomScalar'] | null)
__typename: 'Repository'
}
Expand Down Expand Up @@ -161,6 +162,7 @@ export interface RecursiveTypeGenqlSelection{
export interface RepositoryGenqlSelection{
createdAt?: boolean | number
forks?: (ForkConnectionGenqlSelection & { __args?: {filter?: (Scalars['String'] | null)} })
scalarButWithRequiredArgs?: { __args: {x: Scalars['Int']} }
customScalar?: boolean | number
__typename?: boolean | number
__scalar?: boolean | number
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ export default {
]
}
],
"scalarButWithRequiredArgs": [
4,
{
"x": [
6,
"Int!"
]
}
],
"customScalar": [
2
],
Expand Down
1 change: 1 addition & 0 deletions integration-tests/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type RecursiveType {
type Repository {
createdAt: String!
forks(filter: String): ForkConnection
scalarButWithRequiredArgs(x: Int!): String!
customScalar: MyCustomScalar
}

Expand Down
24 changes: 23 additions & 1 deletion integration-tests/tests/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ describe('execute queries', async function () {
res?.account
// no optional chaining because repository is non null
expectType<string>(res.repository.createdAt)
// TODO
// expectType<never>(res.repository.scalarButWithRequiredArgs)

expectType<Maybe<string>>(res.repository.__typename)
expectType<Maybe<Maybe<string>[]>>(
Expand All @@ -254,7 +256,7 @@ describe('execute queries', async function () {
}),
)
it(
'custom scalar',
'typed custom scalar',
withServer(async () => {
const res = await client.query({
repository: {
Expand All @@ -277,10 +279,30 @@ describe('execute queries', async function () {

let customScalar = res.repository.customScalar
assert(customScalar)
customScalar.x

expectType<Maybe<{ x: string }>>(res.repository.customScalar)
}),
)
it(
'typed custom scalar with __scalar',
withServer(async () => {
const res = await client.query({
repository: {
__args: {
name: 'genql',
owner: 'remorses',
},
__scalar: true,
},
})
console.log(JSON.stringify(res, null, 2))
// TODO
// res.repository.customScalar
}),
)

type t = { __args?: {} } extends { __args: any } ? 'ciao' : never

it(
'union types only 1 on_ normal syntax',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"@types/mocha": "^10.0.1",
"esno": "0.14.1",
"graphql": "^16.6.0",
"native-fetch": "^4.0.2",
"lerna": "^6.0.3",
"native-fetch": "^4.0.2",
"sucrase": "^3.29.0",
"typescript": "4.8"
"typescript": "~5.3.3"
}
}
Loading

0 comments on commit 982dcd3

Please sign in to comment.