Skip to content

Commit

Permalink
custom scalars work
Browse files Browse the repository at this point in the history
  • Loading branch information
remorses committed Jan 15, 2024
1 parent 5415c63 commit 95e94d2
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 99 deletions.
44 changes: 44 additions & 0 deletions architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
i have a query made like this

```ts
type ObjectTypeReq = {
args: ArgsType,
select: Record<string, TypeReq>
include: Record<string, TypeReq>
}

type UnionTypeReq = {
args: ArgsType,
select: Record<string, TypeReq>
include: Record<string, TypeReq>
onA: ObjectTypeReq
onB: ObjectTypeReq
}

type TypeReq = ObjectTypeReq | UnionTypeReq | boolean

getCountries(req: TypeReq): Type
```

i need to create a class Client with top level methods:

```ts
class Client {
getCountries<Include>(req: ObjectTypeReq): Countries<Include> {
const { query, variables } = buildQuery(req, 'getCountries')
}
}

function buildQuery()
```

what if instead it used the builder pattern?

```ts
client.getContinents({
name: '',
include: {
countries: true,
},
})
```
2 changes: 1 addition & 1 deletion cli/src/render/typeMap/renderTypeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isInterfaceType,
isObjectType,
isScalarType,

isUnionType,
} from 'graphql'
import { excludedTypes } from '../common/excludedTypes'
Expand Down Expand Up @@ -67,7 +68,6 @@ export const renderTypeMap = (schema: GraphQLSchema, ctx: RenderContext) => {
ctx.addCodeBlock(
JSON.stringify(replaceTypeNamesWithIndexes(result), null, 4),
)



}
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ enum SomeEnum2 {
world
}

scalar MyCustomScalar

input InputWithRequiredFields {
requiredField: String!
optionalField: String
Expand Down Expand Up @@ -42,6 +44,7 @@ type RecursiveType {
type Repository {
createdAt: String!
forks(filter: String): ForkConnection
customScalar: MyCustomScalar
}

type ForkConnection {
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/* eslint-disable */

export type Scalars = {
MyCustomScalar: any,
String: string,
Int: number,
Float: number,
Expand Down Expand Up @@ -41,6 +42,7 @@ export interface RecursiveType {
export interface Repository {
createdAt: Scalars['String']
forks: (ForkConnection | null)
customScalar: (Scalars['MyCustomScalar'] | null)
__typename: 'Repository'
}

Expand Down Expand Up @@ -159,6 +161,7 @@ export interface RecursiveTypeGenqlSelection{
export interface RepositoryGenqlSelection{
createdAt?: boolean | number
forks?: (ForkConnectionGenqlSelection & { __args?: {filter?: (Scalars['String'] | null)} })
customScalar?: boolean | number
__typename?: boolean | number
__scalar?: boolean | number
}
Expand Down

0 comments on commit 95e94d2

Please sign in to comment.