diff --git a/packages/codegen/package.json b/packages/codegen/package.json index 26fabd833..895626d48 100644 --- a/packages/codegen/package.json +++ b/packages/codegen/package.json @@ -28,6 +28,7 @@ "gql-generator": "https://github.com/vulcanize/gql-generator.git", "graphql": "^15.5.0", "graphql-compose": "^9.0.3", + "pluralize": "^8.0.0", "handlebars": "^4.7.7", "js-yaml": "^4.0.0", "lodash": "^4.17.21", @@ -40,6 +41,7 @@ "devDependencies": { "@openzeppelin/contracts": "^4.3.2", "@types/js-yaml": "^4.0.3", + "@types/pluralize": "^0.0.29", "@types/lodash": "^4.14.168", "@types/node": "^16.9.0", "@types/yargs": "^17.0.0", diff --git a/packages/codegen/src/schema.ts b/packages/codegen/src/schema.ts index fe88829ca..41b19fa43 100644 --- a/packages/codegen/src/schema.ts +++ b/packages/codegen/src/schema.ts @@ -8,6 +8,7 @@ import { ObjectTypeComposer, NonNullComposer, ObjectTypeComposerDefinition, Obje import { Writable } from 'stream'; import { utils } from 'ethers'; import { VariableDeclaration } from '@solidity-parser/parser/dist/src/ast-types'; +import pluralize from 'pluralize'; import { getGqlForSol } from './utils/type-mappings'; import { Param } from './utils/types'; @@ -197,6 +198,7 @@ export class Schema { }; // TODO: Add query type filter (subgraphType_filter) (input) + // Add plural query // Create the subgraphType_orderBy enum type const subgraphTypeOrderByEnum = new GraphQLEnumType({ @@ -208,14 +210,14 @@ export class Schema { }); this._composer.addSchemaMustHaveType(subgraphTypeOrderByEnum); - // Add plural query - // TODO: Use pluralize - const pluralQueryName = `${queryName}s`; + // Create plural query name + // Append suffix 's' if pluralized name is the same as singular name (eg. PoolDayData) + let pluralQueryName = pluralize(queryName); + pluralQueryName = (pluralQueryName === queryName) ? `${pluralQueryName}s` : pluralQueryName; queryObject[pluralQueryName] = { // Get type composer object for return type from the schema composer. - // TODO: make non null - type: [this._composer.getAnyTC(subgraphType).NonNull], + type: this._composer.getAnyTC(subgraphType).NonNull.List.NonNull, args: { // where: Staker_filter, block: BlockHeight, @@ -414,7 +416,7 @@ export class Schema { _addEventsQuery (): void { this._composer.Query.addFields({ events: { - type: [this._composer.getOTC('ResultEvent').NonNull], + type: this._composer.getOTC('ResultEvent').NonNull.List, args: { blockHash: 'String!', contractAddress: 'String!', @@ -425,7 +427,7 @@ export class Schema { this._composer.Query.addFields({ eventsInRange: { - type: [this._composer.getOTC('ResultEvent').NonNull], + type: this._composer.getOTC('ResultEvent').NonNull.List, args: { fromBlockNumber: 'Int!', toBlockNumber: 'Int!'