Skip to content

Commit

Permalink
fix: types are plain objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Jun 12, 2023
1 parent 9c49d82 commit 29dd03e
Showing 1 changed file with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import {
} from "../helpers"

import { buildDefaultResolver } from "./default-resolver"
import {
GraphQLScalarType,
GraphQLList,
GraphQLNonNull,
isListType,
isNonNullType,
} from "graphql"

/**
* @param {import("graphql").GraphQLField} field
Expand All @@ -32,41 +25,28 @@ const handleCustomScalars = field => {
// type it as JSON
return {
...field,
type: new GraphQLScalarType({
type: {
...field.type,
name: `JSON`,
}),
},
}
}

const fieldTypeOfTypeIsACustomScalar =
field.type.ofType &&
field.type.ofType.kind === `SCALAR` &&
!typeIsASupportedScalar(field.type)
field.type.ofType?.kind === `SCALAR` && !typeIsASupportedScalar(field.type)

if (fieldTypeOfTypeIsACustomScalar) {
// if this field is an unsupported custom scalar,
// type it as JSON

if (isListType(field.type)) {
return {
...field,
type: new GraphQLList(
new GraphQLScalarType({
name: `JSON`,
})
),
}
}

if (isNonNullType(field.type)) {
return {
...field,
type: new GraphQLNonNull(
new GraphQLScalarType({
name: `JSON`,
})
),
}
return {
...field,
type: {
...field.type,
ofType: {
...field.type.ofType,
name: `JSON`,
},
},
}
}

Expand Down

0 comments on commit 29dd03e

Please sign in to comment.