Skip to content

Commit

Permalink
Use pluralize for plural query names
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Oct 30, 2023
1 parent c09a25a commit 91794ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
16 changes: 9 additions & 7 deletions packages/codegen/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand Down Expand Up @@ -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!',
Expand All @@ -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!'
Expand Down

0 comments on commit 91794ab

Please sign in to comment.