Skip to content

Commit

Permalink
fix(sdk): fix generated interfaces and SortQueryInput enum
Browse files Browse the repository at this point in the history
  • Loading branch information
bahdcoder committed Nov 10, 2021
1 parent 431f08e commit 0557a08
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/rest/src/sdk/generators/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,18 @@ const getBaseTypes = () => {
export type DateString = string
export type Decimal = number
export type ID = number
export enum SortQueryInput {
ASC = 'asc',
ASC_NULLS_LAST = 'asc_nulls_last',
ASC_NULLS_FIRST = 'asc_nulls_first',
DESC = 'desc',
DESC_NULLS_LAST = 'desc_nulls_last',
DESC_NULLS_FIRST = 'desc_nulls_first',
}
export interface PaginationOptions {
page: number
perPage: number
}
export declare enum SortQueryInput {
ASC = "asc",
ASC_NULLS_LAST = "asc_nulls_last",
ASC_NULLS_FIRST = "asc_nulls_first",
DESC = "desc",
DESC_NULLS_LAST = "desc_nulls_last",
DESC_NULLS_FIRST = "desc_nulls_first"
}
export type FindResponse<Resource> = AxiosResponse<{
data: Resource
}>
Expand Down Expand Up @@ -145,6 +144,12 @@ const getRelationshipFieldsForRelatedResource = (
)
}

const getImports = () => {
return `
import { AxiosResponse } from 'axios'
`
}

const getResourcePopulateFields = (
resource: ResourceContract,
resources: ResourceContract[]
Expand Down Expand Up @@ -196,7 +201,7 @@ const getResourceFieldsSelectList = (resource: ResourceContract) => {
field => !field.showHideFieldFromApi.hideOnFetchApi && !field.isHidden
)

if (possibleSelectFields.length > 0) {
if (possibleSelectFields.length === 0) {
return `export type ${resource.data.pascalCaseName}SelectFields = ''`
}

Expand Down Expand Up @@ -326,7 +331,7 @@ const getInsertResourceInterface = (
}

return `
export interface ${resource.data.pascalCaseName}InsertInput {
export interface ${resource.data.pascalCaseName}CreateInput {
${resource.data.fields
.filter(
field =>
Expand Down Expand Up @@ -410,6 +415,7 @@ export const generateResourceInterfaces = async ({
resources
}: PluginSetupConfig) => {
return `
${getImports()}
${resources
.map(
resource => `
Expand Down
9 changes: 9 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ export class Sdk extends BaseSdk {
}

export const sdk = (options?: SdkOptions) => new Sdk(options)

export enum SortQueryInput {
ASC = 'asc',
ASC_NULLS_LAST = 'asc_nulls_last',
ASC_NULLS_FIRST = 'asc_nulls_first',
DESC = 'desc',
DESC_NULLS_LAST = 'desc_nulls_last',
DESC_NULLS_FIRST = 'desc_nulls_first'
}

0 comments on commit 0557a08

Please sign in to comment.