libero / reviewer

Libero Reviewer
https://libero.pub
MIT License
11 stars 3 forks source link

Issue with AuthorDetails in typescript and GraphQL being misaligned #1043

Closed erezmus closed 4 years ago

erezmus commented 4 years ago

Currently, we have in the GraphQL definition:

type AuthorDetails {
    firstName: String!
    lastName: String!
    email: String!
    institution: String!
}

and

type Submission {
  //...
  author: AuthorDetails
  //...
}

In typescript, we have:

export type AuthorDetails = {
    firstName: string;
    lastName: string;
    email: string;
    aff: string;
};

the GraphQL and TS differ by "institution" field being named as "aff". However we are saving the teamMember for authors with "institution" rather than "aff":

          role           |                                                                              team_members                                                                               
--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 author                   | {"{\"meta\": {\"corresponding\": true}, \"alias\": {\"email\": \"jimmy@doe.com\", \"lastName\": \"doe\", \"firstName\": \"jimmy\", \"institution\": \"institution\"}}"}

therefore when we have an AuthorDetails object in typescript, it actually doesn't have an "aff" field but an "institution" field. This is causing issues for instance when doing the validation for submission as its expecting there to be an aff field:

        aff: Joi.string().required(),

Solutions:

  1. Rename aff to institution in typescript type. However, i think we are using 'aff' in xpub.

  2. Change the client to use 'aff' instead of 'institution'. I'm not sure of all the ramifications for this so will need advice.

  3. Convert from 'institution' => 'aff' at resolver level and then change it back to 'institution' when sending the Submission object back. However we would need to have a separate Submission type to send back because the AuthorDetails don't match between Typescript and GraphQL

  4. Same as 3 but at the repository level with the same issue that we would need to use slightly different types for the DatabaseEntry's team_members field (AuthorTeamMember specifically)

erezmus commented 4 years ago

@Cooryd @will-byrne If you could comment on number 2 that would be great as you have more experience with the client

erezmus commented 4 years ago

checked on xpub and we are storing as 'aff':

 author | {"{\"meta\": {\"corresponding\": true}, \"alias\": {\"aff\": \"Tech team, University of eLife\", \"email\": \"test@example.com\", \"lastName\": \"Swartz\", \"firstName\": \"Aaron\"}}"}
diversemix commented 4 years ago

ok - let's use that then - don't care really what we use in the GraphQL - as long as it get's mapped to aff in the database :+1:

erezmus commented 4 years ago

@diversemix sorry which option?

erezmus commented 4 years ago

after discussing with rest of team, option 4 has been chosen