Skip to content

modify some graphql types to Enum#39

Merged
FrancisMurilloDigix merged 13 commits intofeature/sprint-8dfrom
feature/dgdg-532
May 14, 2019
Merged

modify some graphql types to Enum#39
FrancisMurilloDigix merged 13 commits intofeature/sprint-8dfrom
feature/dgdg-532

Conversation

@roynalnaruto
Copy link
Contributor

No description provided.

@mikej-digix mikej-digix changed the base branch from feature/sprint-8c to feature/sprint-8d May 8, 2019 06:12
const { denominators } = require('../helpers/constants');

const typeDef = gql`
enum ProposalPrlEnum {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments or descriptions for each enum.

enum ProposalPrlEnum {
  # This is a description
  STOPPED
}


for (const k in contracts) {
const contract = contracts[k];
console.log('constract name = ', contract.contractName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this console optional

NEW: 'ACTIVE',
};

const proposalStages = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have preferred normal cased keys like so

const proposalStages = {
  idea: 'IDEA',
  draft: 'DRAFT',
  proposal: 'PROPOSAL',
  ongoing: 'ONGOING',
  review: 'REVIEW',
  archived: 'ARCHIVED',
};

This is fine but CONSTANT_NAMES like these are a fragment of global constant naming so it has perhaps fallen out of favor. Its okay nonetheless.

# Get actionable statuses for proposals with proposalIds
getActionableStatus(proposalIds: [String!]): [ProposalActionableObject]
# Find proposals in specific stage
fetchProposals(stage: String!, onlyActionable: Boolean): [Proposal]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is stage required? stage: String instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you use ProposalStageEnum instead of just String?

graphql.js Outdated
const { stage, onlyActionable } = args;
const filter = (stage === 'all') ? {} : { stage: stage.toUpperCase() };
const proposals = await getProposals(filter);
let specialProposals = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about usingconst and a ternary to avoid let declaration?


# Any actionable status
actionableStatus: ProposalActionableStatusEnum
actionableStatus: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use String over ProposalActionableStatusEnum?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ProposalActionableStatusEnum be nullable? Is this null when there is no current user? Based on the code it is NONE instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.apollographql.com/docs/graphql-tools/scalars#enums
according to this, I would have to use enum fields like "AWAITING_ENDORSEMENT". But I would like to return strings that replace those underscores with spaces.

graphql.js Outdated
actionableStatus: status.replace('_', ' '),
};
});
if (onlyActionable) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

const allProposals = specialProposals.concat(proposals).map(proposal => ({
          ...proposal,
          actionableStatus: getCurrentActionableStatus(proposal, context.currentUser),
}))

return onlyActionable ? 
  allProposals.filter(proposal => proposal.actionableStatus !== actionableStatus.NONE) :
  allProposals

const status = getCurrentActionableStatus(proposal, user);
return status.replace('_', ' ');
actionableStatus(proposal, _args, context, _info) {
if (proposal.actionableStatus && proposal.actionableStatus !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about putting the guard condition first to avoid the lets statement?

if (!context.currentUser) {
  return actionableStatus.NONE;
}

const status = proposal.actionableStatus || getCurrentActionableStatus(proposal, context.currentUser);

return status.split('_').join(' ');  

Copy link
Contributor

@FrancisMurilloDigix FrancisMurilloDigix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@FrancisMurilloDigix FrancisMurilloDigix merged commit 4303e2b into feature/sprint-8d May 14, 2019
@FrancisMurilloDigix FrancisMurilloDigix deleted the feature/dgdg-532 branch May 14, 2019 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants