-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generated publishers are now all camel-cased
BREAKING CHANGE: publishers accessed using old lower-case naming will break
- Loading branch information
Showing
5 changed files
with
391 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,341 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`generates publishers pluralized & camel-cased: schema 1`] = ` | ||
"type BatchPayload { | ||
count: Int! | ||
} | ||
input IntFilter { | ||
equals: Int | ||
not: Int | ||
in: [Int!] | ||
notIn: [Int!] | ||
lt: Int | ||
lte: Int | ||
gt: Int | ||
gte: Int | ||
} | ||
type ModelName { | ||
id: Int! | ||
} | ||
input ModelNameCreateInput { | ||
name: String! | ||
} | ||
input ModelNameUpdateInput { | ||
id: Int | ||
name: String | ||
} | ||
input ModelNameUpdateManyMutationInput { | ||
id: Int | ||
name: String | ||
} | ||
input ModelNameWhereInput { | ||
id: IntFilter | ||
name: StringFilter | ||
AND: [ModelNameWhereInput!] | ||
OR: [ModelNameWhereInput!] | ||
NOT: [ModelNameWhereInput!] | ||
} | ||
input ModelNameWhereUniqueInput { | ||
id: Int | ||
} | ||
type Mutation { | ||
createOneModelName(data: ModelNameCreateInput!): ModelName! | ||
deleteOneModelName(where: ModelNameWhereUniqueInput!): ModelName | ||
updateOneModelName(data: ModelNameUpdateInput!, where: ModelNameWhereUniqueInput!): ModelName | ||
upsertOneModelName(where: ModelNameWhereUniqueInput!, create: ModelNameCreateInput!, update: ModelNameUpdateInput!): ModelName! | ||
updateManyModelName(data: ModelNameUpdateManyMutationInput!, where: ModelNameWhereInput): BatchPayload! | ||
} | ||
type Query { | ||
modelName(where: ModelNameWhereUniqueInput!): ModelName | ||
modelNames(skip: Int, after: String, before: String, first: Int, last: Int): [ModelName!]! | ||
} | ||
input StringFilter { | ||
equals: String | ||
not: String | ||
in: [String!] | ||
notIn: [String!] | ||
lt: String | ||
lte: String | ||
gt: String | ||
gte: String | ||
contains: String | ||
startsWith: String | ||
endsWith: String | ||
} | ||
" | ||
`; | ||
|
||
exports[`generates publishers pluralized & camel-cased: typegen 1`] = ` | ||
"import * as photon from '@generated/photon'; | ||
import { core } from 'nexus'; | ||
// Types helpers | ||
type IsModelNameExistsInGraphQLTypes< | ||
ReturnType extends any | ||
> = ReturnType extends core.GetGen<'objectNames'> ? true : false; | ||
type NexusPrismaScalarOpts = { | ||
alias?: string; | ||
}; | ||
type Pagination = { | ||
first?: boolean; | ||
last?: boolean; | ||
before?: boolean; | ||
after?: boolean; | ||
skip?: boolean; | ||
}; | ||
type RootObjectTypes = Pick< | ||
core.GetGen<'rootTypes'>, | ||
core.GetGen<'objectNames'> | ||
>; | ||
/** | ||
* Determine if \`B\` is a subset (or equivalent to) of \`A\`. | ||
*/ | ||
type IsSubset<A, B> = keyof A extends never | ||
? false | ||
: B extends A | ||
? true | ||
: false; | ||
type OmitByValue<T, ValueType> = Pick< | ||
T, | ||
{ [Key in keyof T]: T[Key] extends ValueType ? never : Key }[keyof T] | ||
>; | ||
type GetSubsetTypes<ModelName extends any> = keyof OmitByValue< | ||
{ | ||
[P in keyof RootObjectTypes]: ModelName extends keyof ModelTypes | ||
? IsSubset<RootObjectTypes[P], ModelTypes[ModelName]> extends true | ||
? RootObjectTypes[P] | ||
: never | ||
: never; | ||
}, | ||
never | ||
>; | ||
type SubsetTypes<ModelName extends any> = GetSubsetTypes< | ||
ModelName | ||
> extends never | ||
? \`ERROR: No subset types are available. Please make sure that one of your GraphQL type is a subset of your t.model('<ModelName>')\` | ||
: GetSubsetTypes<ModelName>; | ||
type DynamicRequiredType<ReturnType extends any> = IsModelNameExistsInGraphQLTypes< | ||
ReturnType | ||
> extends true | ||
? { type?: SubsetTypes<ReturnType> } | ||
: { type: SubsetTypes<ReturnType> }; | ||
type GetNexusPrismaInput< | ||
ModelName extends any, | ||
MethodName extends any, | ||
InputName extends 'filtering' | 'ordering' | ||
> = ModelName extends keyof NexusPrismaInputs | ||
? MethodName extends keyof NexusPrismaInputs[ModelName] | ||
? NexusPrismaInputs[ModelName][MethodName][InputName] | ||
: never | ||
: never; | ||
type NexusPrismaRelationOpts< | ||
ModelName extends any, | ||
MethodName extends any, | ||
ReturnType extends any | ||
> = GetNexusPrismaInput< | ||
// If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. So just use \`alias\` and \`type\` | ||
ModelName, | ||
MethodName, | ||
'filtering' | ||
> extends never | ||
? { | ||
alias?: string; | ||
} & DynamicRequiredType<ReturnType> | ||
: { | ||
alias?: string; | ||
filtering?: | ||
| boolean | ||
| Partial< | ||
Record< | ||
GetNexusPrismaInput<ModelName, MethodName, 'filtering'>, | ||
boolean | ||
> | ||
>; | ||
ordering?: | ||
| boolean | ||
| Partial< | ||
Record< | ||
GetNexusPrismaInput<ModelName, MethodName, 'ordering'>, | ||
boolean | ||
> | ||
>; | ||
pagination?: boolean | Pagination; | ||
} & DynamicRequiredType<ReturnType>; | ||
type IsScalar<TypeName extends any> = TypeName extends core.GetGen<'scalarNames'> | ||
? true | ||
: false; | ||
type IsObject<Name extends any> = Name extends core.GetGen<'objectNames'> | ||
? true | ||
: false | ||
type IsEnum<Name extends any> = Name extends core.GetGen<'enumNames'> | ||
? true | ||
: false | ||
type IsInputObject<Name extends any> = Name extends core.GetGen<'inputNames'> | ||
? true | ||
: false | ||
/** | ||
* The kind that a GraphQL type may be. | ||
*/ | ||
type Kind = 'Enum' | 'Object' | 'Scalar' | 'InputObject' | ||
/** | ||
* Helper to safely reference a Kind type. For example instead of the following | ||
* which would admit a typo: | ||
* | ||
* \`\`\`ts | ||
* type Foo = Bar extends 'scalar' ? ... | ||
* \`\`\` | ||
* | ||
* You can do this which guarantees a correct reference: | ||
* | ||
* \`\`\`ts | ||
* type Foo = Bar extends AKind<'Scalar'> ? ... | ||
* \`\`\` | ||
* | ||
*/ | ||
type AKind<T extends Kind> = T | ||
type GetKind<Name extends any> = IsEnum<Name> extends true | ||
? 'Enum' | ||
: IsScalar<Name> extends true | ||
? 'Scalar' | ||
: IsObject<Name> extends true | ||
? 'Object' | ||
: IsInputObject<Name> extends true | ||
? 'InputObject' | ||
// FIXME should be \`never\`, but GQL objects named differently | ||
// than backing type fall into this branch | ||
: 'Object' | ||
type NexusPrismaFields<ModelName extends keyof NexusPrismaTypes> = { | ||
[MethodName in keyof NexusPrismaTypes[ModelName]]: NexusPrismaMethod< | ||
ModelName, | ||
MethodName, | ||
GetKind<NexusPrismaTypes[ModelName][MethodName]> // Is the return type a scalar? | ||
>; | ||
}; | ||
type NexusPrismaMethod< | ||
ModelName extends keyof NexusPrismaTypes, | ||
MethodName extends keyof NexusPrismaTypes[ModelName], | ||
ThisKind extends Kind, | ||
ReturnType extends any = NexusPrismaTypes[ModelName][MethodName] | ||
> = | ||
ThisKind extends AKind<'Enum'> | ||
? () => NexusPrismaFields<ModelName> | ||
: ThisKind extends AKind<'Scalar'> | ||
? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields<ModelName> // Return optional scalar opts | ||
: IsModelNameExistsInGraphQLTypes<ReturnType> extends true // If model name has a mapped graphql types | ||
? ( | ||
opts?: NexusPrismaRelationOpts<ModelName, MethodName, ReturnType> | ||
) => NexusPrismaFields<ModelName> // Then make opts optional | ||
: ( | ||
opts: NexusPrismaRelationOpts<ModelName, MethodName, ReturnType> | ||
) => NexusPrismaFields<ModelName>; // Else force use input the related graphql type -> { type: '...' } | ||
type GetNexusPrismaMethod< | ||
TypeName extends string | ||
> = TypeName extends keyof NexusPrismaMethods | ||
? NexusPrismaMethods[TypeName] | ||
: <CustomTypeName extends keyof ModelTypes>( | ||
typeName: CustomTypeName | ||
) => NexusPrismaMethods[CustomTypeName]; | ||
type GetNexusPrisma< | ||
TypeName extends string, | ||
ModelOrCrud extends 'model' | 'crud' | ||
> = ModelOrCrud extends 'model' | ||
? TypeName extends 'Mutation' | ||
? never | ||
: TypeName extends 'Query' | ||
? never | ||
: GetNexusPrismaMethod<TypeName> | ||
: ModelOrCrud extends 'crud' | ||
? TypeName extends 'Mutation' | ||
? GetNexusPrismaMethod<TypeName> | ||
: TypeName extends 'Query' | ||
? GetNexusPrismaMethod<TypeName> | ||
: never | ||
: never; | ||
// Generated | ||
interface ModelTypes { | ||
ModelName: photon.ModelName | ||
} | ||
interface NexusPrismaInputs { | ||
Query: { | ||
modelNames: { | ||
filtering: 'id' | 'name' | 'AND' | 'OR' | 'NOT' | ||
ordering: 'id' | 'name' | ||
} | ||
}, | ||
ModelName: { | ||
} | ||
} | ||
interface NexusPrismaTypes { | ||
Query: { | ||
modelName: 'ModelName' | ||
modelNames: 'ModelName' | ||
}, | ||
Mutation: { | ||
createOneModelName: 'ModelName' | ||
updateOneModelName: 'ModelName' | ||
updateManyModelName: 'BatchPayload' | ||
deleteOneModelName: 'ModelName' | ||
deleteManyModelName: 'BatchPayload' | ||
upsertOneModelName: 'ModelName' | ||
}, | ||
ModelName: { | ||
id: 'Int' | ||
name: 'String' | ||
} | ||
} | ||
interface NexusPrismaMethods { | ||
ModelName: NexusPrismaFields<'ModelName'> | ||
Query: NexusPrismaFields<'Query'> | ||
Mutation: NexusPrismaFields<'Mutation'> | ||
} | ||
declare global { | ||
type NexusPrisma< | ||
TypeName extends string, | ||
ModelOrCrud extends 'model' | 'crud' | ||
> = GetNexusPrisma<TypeName, ModelOrCrud>; | ||
} | ||
" | ||
`; |
Oops, something went wrong.