Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improv(client): Return JsonValue type #2602

Merged
merged 4 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/packages/client/src/generation/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ export declare const prismaVersion: PrismaVersion
* Utility Types
*/

/**
* From https://github.com/sindresorhus/type-fest/
* Matches a JSON object.
* This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from.
*/
declare type JsonObject = {[Key in string]?: JsonValue}

/**
* From https://github.com/sindresorhus/type-fest/
* Matches a JSON array.
*/
declare interface JsonArray extends Array<JsonValue> {}

/**
* From https://github.com/sindresorhus/type-fest/
* Matches any valid JSON value.
*/
declare type JsonValue = string | number | boolean | null | Date | JsonObject | JsonArray
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you guys convert Dates? Its not a JSON primitive.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mention this here as well prisma/prisma-client-js#691 but this breaks the JSON specification. It gives TypeScript errors when trying to send the value through an API that encodes/decodes to JSON like Next.js


declare type SelectAndInclude = {
select: any
include: any
Expand All @@ -153,7 +172,6 @@ declare type HasInclude = {
include: any
}


declare type CheckSelect<T, S, U> = T extends SelectAndInclude
? 'Please either choose \`select\` or \`include\`'
: T extends HasSelect
Expand Down
2 changes: 1 addition & 1 deletion src/packages/client/src/runtime/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const GraphQLScalarToJSTypeTable = {
DateTime: ['Date', 'string'],
ID: 'string',
UUID: 'string',
Json: 'object',
Json: 'JsonValue',
}

export const JSTypeToGraphQLType = {
Expand Down