Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Jul 9, 2024
1 parent 3af413e commit 515f37b
Show file tree
Hide file tree
Showing 17 changed files with 58,900 additions and 162 deletions.
21 changes: 17 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions graphql/openreader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"graphql-parse-resolve-info": "^4.14.0",
"graphql-ws": "^5.14.2",
"pg": "^8.11.3",
"ws": "^8.14.2"
"ws": "^8.14.2",
"inflected": "^2.1.0"
},
"peerDependencies": {
"@subsquid/big-decimal": "^1.0.0"
Expand All @@ -63,6 +64,7 @@
"expect": "^29.7.0",
"gql-test-client": "^0.0.0",
"mocha": "^10.2.0",
"typescript": "~5.3.2"
"typescript": "~5.3.2",
"@types/inflected": "^2.1.3"
}
}
24 changes: 20 additions & 4 deletions graphql/openreader/src/dialect/opencrud/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {getOrderByMapping, parseOrderBy} from './orderBy'
import {parseAnyTree, parseObjectTree, parseSqlArguments} from './tree'
import {parseWhere} from './where'
import {GqlFieldMap, SchemaOptions} from '../common'
import {Where} from '../../ir/args'


export class SchemaBuilder {
Expand Down Expand Up @@ -395,7 +396,7 @@ export class SchemaBuilder {

private installListQuery(typeName: string, query: GqlFieldMap, subscription: GqlFieldMap): void {
let model = this.model
let queryName = toPlural(toCamelCase(typeName))
let queryName = this.normalizeEntityName(typeName).plural
let outputType = new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(this.get(typeName))))
let argsType = this.listArguments(typeName)

Expand Down Expand Up @@ -435,7 +436,7 @@ export class SchemaBuilder {

private installEntityById(entityName: string, query: GqlFieldMap, subscription: GqlFieldMap): void {
let model = this.model
let queryName = `${toCamelCase(entityName)}ById`
let queryName = `${this.normalizeEntityName(entityName).singular}ById`
let argsType = {
id: {type: new GraphQLNonNull(GraphQLString)}
}
Expand Down Expand Up @@ -476,7 +477,7 @@ export class SchemaBuilder {
private installEntityByUniqueInput(entityName: string, query: GqlFieldMap): void {
let model = this.model

query[`${toCamelCase(entityName)}ByUniqueInput`] = {
query[`${this.normalizeEntityName(entityName).singular}ByUniqueInput`] = {
deprecationReason: `Use ${toCamelCase(entityName)}ById`,
type: this.get(entityName),
args: {
Expand Down Expand Up @@ -505,7 +506,7 @@ export class SchemaBuilder {
let outputType = toPlural(typeName) + 'Connection'
let edgeType = `${typeName}Edge`

query[`${toPlural(toCamelCase(typeName))}Connection`] = {
query[`${this.normalizeEntityName(typeName).plural}Connection`] = {
type: new GraphQLNonNull(new GraphQLObjectType({
name: outputType,
fields: {
Expand Down Expand Up @@ -619,6 +620,21 @@ export class SchemaBuilder {
})
)
}

private normalizeEntityName(typeName: string) {
let model = this.model[typeName]

let singular = toCamelCase(typeName)

let plural: string
if (model.kind === 'entity' && model.plural != null) {
plural = toCamelCase(model.plural)
} else {
plural = toPlural(singular)
}

return {singular, plural}
}
}


Expand Down
Loading

0 comments on commit 515f37b

Please sign in to comment.