Skip to content

Commit

Permalink
ResourceUnion
Browse files Browse the repository at this point in the history
  • Loading branch information
Fi1osof committed Mar 4, 2021
1 parent 1e297b1 commit 7977b66
Show file tree
Hide file tree
Showing 25 changed files with 585 additions and 79 deletions.
5 changes: 5 additions & 0 deletions pages/[...path].tsx
@@ -0,0 +1,5 @@
/**
* Handle all unrouted pages
*/

export { default } from 'src/pages/Resource'
34 changes: 26 additions & 8 deletions server/nexus/generated/nexus.ts
Expand Up @@ -277,6 +277,7 @@ export interface NexusGenObjects {
id: number // Int!
longtitle: string // String!
pagetitle: string // String!
template: number // Int!
uri?: string | null // String
}
Company: {
Expand All @@ -295,6 +296,8 @@ export interface NexusGenObjects {
longtitle: string // String!
pagetitle: string // String!
published: boolean // Boolean!
searchable: boolean // Boolean!
template: number // Int!
uri?: string | null // String
}
Coordinates: {
Expand Down Expand Up @@ -324,6 +327,7 @@ export interface NexusGenObjects {
longtitle: string // String!
pagetitle: string // String!
published: boolean // Boolean!
searchable: boolean // Boolean!
template: number // Int!
uri?: string | null // String
}
Expand All @@ -338,9 +342,14 @@ export interface NexusGenObjects {

export interface NexusGenInterfaces {}

export interface NexusGenUnions {}
export interface NexusGenUnions {
ResourceUnion:
| NexusGenRootTypes['City']
| NexusGenRootTypes['Company']
| NexusGenRootTypes['Resource']
}

export type NexusGenRootTypes = NexusGenObjects
export type NexusGenRootTypes = NexusGenObjects & NexusGenUnions

export type NexusGenAllTypes = NexusGenRootTypes &
NexusGenScalars &
Expand All @@ -357,6 +366,7 @@ export interface NexusGenFieldTypes {
id: number // Int!
longtitle: string // String!
pagetitle: string // String!
template: number // Int!
uri: string | null // String
}
Company: {
Expand All @@ -381,6 +391,8 @@ export interface NexusGenFieldTypes {
pagetitle: string // String!
prices: string | null // String
published: boolean // Boolean!
searchable: boolean // Boolean!
template: number // Int!
uri: string | null // String
workTime: string | null // String
}
Expand All @@ -400,7 +412,7 @@ export interface NexusGenFieldTypes {
// field return type
cities: NexusGenRootTypes['City'][] // [City!]!
companies: NexusGenRootTypes['Company'][] // [Company!]!
resources: NexusGenRootTypes['Resource'][] // [Resource!]!
resources: NexusGenRootTypes['ResourceUnion'][] // [ResourceUnion!]!
}
Resource: {
// field return type
Expand All @@ -416,6 +428,7 @@ export interface NexusGenFieldTypes {
longtitle: string // String!
pagetitle: string // String!
published: boolean // Boolean!
searchable: boolean // Boolean!
template: number // Int!
uri: string | null // String
}
Expand All @@ -437,6 +450,7 @@ export interface NexusGenFieldTypeNames {
id: 'Int'
longtitle: 'String'
pagetitle: 'String'
template: 'Int'
uri: 'String'
}
Company: {
Expand All @@ -459,6 +473,8 @@ export interface NexusGenFieldTypeNames {
pagetitle: 'String'
prices: 'String'
published: 'Boolean'
searchable: 'Boolean'
template: 'Int'
uri: 'String'
workTime: 'String'
}
Expand All @@ -478,7 +494,7 @@ export interface NexusGenFieldTypeNames {
// field return type name
cities: 'City'
companies: 'Company'
resources: 'Resource'
resources: 'ResourceUnion'
}
Resource: {
// field return type name
Expand All @@ -492,6 +508,7 @@ export interface NexusGenFieldTypeNames {
longtitle: 'String'
pagetitle: 'String'
published: 'Boolean'
searchable: 'Boolean'
template: 'Int'
uri: 'String'
}
Expand Down Expand Up @@ -524,7 +541,6 @@ export interface NexusGenArgTypes {
}
resources: {
// args
cursor?: NexusGenInputs['bani684_site_contentWhereUniqueInput'] | null // bani684_site_contentWhereUniqueInput
orderBy?: NexusGenInputs['bani684_site_contentOrderByInput'][] | null // [bani684_site_contentOrderByInput!]
skip?: number | null // Int
take?: number | null // Int
Expand All @@ -533,7 +549,9 @@ export interface NexusGenArgTypes {
}
}

export interface NexusGenAbstractTypeMembers {}
export interface NexusGenAbstractTypeMembers {
ResourceUnion: 'City' | 'Company' | 'Resource'
}

export interface NexusGenTypeInterfaces {}

Expand All @@ -547,11 +565,11 @@ export type NexusGenInterfaceNames = never

export type NexusGenScalarNames = keyof NexusGenScalars

export type NexusGenUnionNames = never
export type NexusGenUnionNames = keyof NexusGenUnions

export type NexusGenObjectsUsingAbstractStrategyIsTypeOf = never

export type NexusGenAbstractsUsingStrategyResolveType = never
export type NexusGenAbstractsUsingStrategyResolveType = 'ResourceUnion'

export type NexusGenFeaturesConfig = {
abstractTypeStrategies: {
Expand Down
12 changes: 10 additions & 2 deletions server/nexus/generated/schema.graphql
Expand Up @@ -26,6 +26,7 @@ type City {
id: Int!
longtitle: String!
pagetitle: String!
template: Int!
uri: String
}

Expand Down Expand Up @@ -67,6 +68,8 @@ type Company {
"""
prices: String
published: Boolean!
searchable: Boolean!
template: Int!
uri: String

"""
Expand Down Expand Up @@ -178,12 +181,11 @@ type Query {
Ресурсы
"""
resources(
cursor: bani684_site_contentWhereUniqueInput
orderBy: [bani684_site_contentOrderByInput!]
skip: Int
take: Int
where: bani684_site_contentWhereInput
): [Resource!]!
): [ResourceUnion!]!
}

type Resource {
Expand All @@ -197,10 +199,16 @@ type Resource {
longtitle: String!
pagetitle: String!
published: Boolean!
searchable: Boolean!
template: Int!
uri: String
}

"""
Компания, Город или иной ресурс
"""
union ResourceUnion = City | Company | Resource

enum SortOrder {
asc
desc
Expand Down
1 change: 1 addition & 0 deletions server/nexus/types/City.ts
Expand Up @@ -12,6 +12,7 @@ export const City = objectType({
t.nonNull.int('id')
t.nonNull.string('pagetitle')
t.nonNull.string('longtitle')
t.nonNull.int('template')
t.string('uri')
t.string('alias')
// t.field('coords', {
Expand Down
3 changes: 2 additions & 1 deletion server/nexus/types/Company.ts
Expand Up @@ -21,8 +21,9 @@ export const Company = objectType({
t.string('content')
t.string('uri')
t.string('alias')
// t.nonNull.int("template")
t.nonNull.int('template')
t.nonNull.boolean('published')
t.nonNull.boolean('searchable')
// t.nonNull.date("publishedon")
t.nonNull.int('editedby')
t.nonNull.date('editedon')
Expand Down
1 change: 1 addition & 0 deletions server/nexus/types/Query/definitions/City.ts
Expand Up @@ -59,6 +59,7 @@ export const cities = (t: ObjectDefinitionBlock<'Query'>) => {
// createdon: true,
// editedby: true,
// editedon: true,
template: true,
TemplateVarValues: {
select: {
id: true,
Expand Down
24 changes: 18 additions & 6 deletions server/nexus/types/Query/definitions/Resource.ts
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/ban-ts-ignore */

import { ObjectDefinitionBlock } from 'nexus/dist/core'
import { list, nonNull, ObjectDefinitionBlock } from 'nexus/dist/core'
import { Prisma } from '@prisma/client'

export const resources = (t: ObjectDefinitionBlock<'Query'>) => {
Expand All @@ -21,12 +21,20 @@ export const resources = (t: ObjectDefinitionBlock<'Query'>) => {
// take: 'Int',
// skip: 'Int',
// },
t.crud.bani684SiteContents({
alias: 'resources',
// t.crud.bani684SiteContents({

t.nonNull.list.nonNull.field('resources', {
// alias: 'resources',
description: 'Ресурсы',
type: 'Resource',
ordering: true,
filtering: true,
type: 'ResourceUnion',
// ordering: true,
// filtering: true,
args: {
where: 'bani684_site_contentWhereInput',
orderBy: list(nonNull('bani684_site_contentOrderByInput')),
take: 'Int',
skip: 'Int',
},
resolve(_, args, ctx) {
const variables = args as Pick<
Prisma.bani684_site_contentFindManyArgs,
Expand Down Expand Up @@ -61,6 +69,7 @@ export const resources = (t: ObjectDefinitionBlock<'Query'>) => {
createdby: true,
createdon: true,
template: true,
searchable: true,
// editedby: true,
// editedon: true,
TemplateVarValues: {
Expand All @@ -71,6 +80,9 @@ export const resources = (t: ObjectDefinitionBlock<'Query'>) => {
value: true,
},
},
content: true,
editedby: true,
editedon: true,
},
// orderBy: {
// pagetitle: "asc",
Expand Down
23 changes: 23 additions & 0 deletions server/nexus/types/Query/index.ts
Expand Up @@ -16,6 +16,29 @@ export const Query = objectType({
resources(t)
// resourcesCount(t)

// t.nonNull.list.field("resources", {
// type: "ResourceUnion",
// resolve: () => {

// return [];
// }
// })

// t.crud.bani684SiteContents({
// alias: 'resources',
// type: ResourceUnion,
// ordering: true,
// filtering: true,
// resolve: async (_, _args, ctx) => {

// // const result = await ctx.prisma.bani684_site_content.count();

// // console.log("bani684ModxsiteCompaniess result", result);

// return [];
// },
// })

// t.crud.bani684SiteContents({
// alias: 'resources',
// type: 'Resource',
Expand Down
2 changes: 2 additions & 0 deletions server/nexus/types/Query/resolvers/companiesResolver.ts
Expand Up @@ -43,6 +43,8 @@ export const companiesResolver: FieldResolver<
createdon: true,
editedby: true,
editedon: true,
template: true,
searchable: true,
TemplateVarValues: {
select: {
id: true,
Expand Down
21 changes: 20 additions & 1 deletion server/nexus/types/Resource.ts
@@ -1,4 +1,4 @@
import { objectType } from 'nexus'
import { objectType, unionType } from 'nexus'

// alias
// city_id
Expand All @@ -14,6 +14,24 @@ import { objectType } from 'nexus'
// mapIcon
// image

export const ResourceUnion = unionType({
name: 'ResourceUnion',
description: 'Компания, Город или иной ресурс',
definition(t) {
t.members('Resource', 'Company', 'City')
},
// resolveType: (item) => item.name,
resolveType: (item) => {
if (item.template === 26) {
return 'City'
} else if (item.template === 27) {
return 'Company'
}

return 'Resource'
},
})

export const Resource = objectType({
name: 'Resource',
// sourceType: {
Expand All @@ -34,6 +52,7 @@ export const Resource = objectType({
t.nonNull.int('template')
t.nonNull.boolean('published')
t.nonNull.int('createdby')
t.nonNull.boolean('searchable')
// t.nonNull.int("editedby")
// t.nonNull.date("editedon")

Expand Down
34 changes: 19 additions & 15 deletions src/gql/city.graphql
Expand Up @@ -15,20 +15,24 @@ query cities(
skip: $skip
where: $where
) {
id
pagetitle
longtitle
alias
uri
coords {
lat
lng
zoom
}
# image
# imageFormats {
# marker_thumb
# }
# parent
...city
}
}

fragment city on City {
id
pagetitle
longtitle
alias
uri
coords {
lat
lng
zoom
}
# image
# imageFormats {
# marker_thumb
# }
# parent
}

0 comments on commit 7977b66

Please sign in to comment.