2
\$\begingroup\$

I am learning about GraphQL so I decided to make a schema for some sort of social network. Please let me know if there are any best practices I should follow based on my schema below.

  scalar DateTime

  type Query {
      # user
      currentUser: User # use request "Authorization" header to get credentials
      getUser(uid: String!): User

      # friends
      getFriendRequest(requestId: Int!): FriendRequest
  }

  type Mutation {
      initializeNewUser: User!
      editCurrentUser(input: EditUserInput): User! 

      # friends
      sendFriendRequest(toUid: String!): FriendRequest
      # from this mutation, can accept or reject friend requests. 
      # server should handle adding of new friend on input.status == RequestStatus.accept
      updateFriendRequest(input: UpdateFriendRequestInput!): FriendRequest!

      # unfriend uid, and return updated list of friends
      unfriend(uid: String!): [Friend!]!
  }


  input UpdateFriendRequestInput {
      requestId: Int!
      status: RequestStatus!
  }


  input EditUserInput {
      displayName: String
      profilePic: String
  }


  type User {
      uid: String!
      profilePic: String
      displayName: String
      createdOn: DateTime!
      isOnline: Boolean
      friends: [Friend!]!
      friendRequests: [FriendRequest!]!
  }


  type Friend {
      user: User!
      friendsSince: DateTime!
      mutualFriends: [Friend!]!
  }


  type FriendRequest {
      requestId: Int!
      requestingUser: User!
      receivingUser: User!
      status: RequestStatus
      requestedAt: DateTime!
  }


  enum RequestStatus {
      pending
      accepted
      rejected
  }
\$\endgroup\$
  • \$\begingroup\$ Welcome to CR! I've created the tag for you, since this is a relatively new technology we didn't have a tag for. I have refrained from unilaterally deciding whether reviewing a GraphQL schema definition is on-topic or not though - I'll cook up a Code Review Meta post for the community to discuss and debate (IMO it's not very different than reviewing a plain SQL schema definition script, which is on-topic here albeit with an overlap with Database Administrators). In the meantime have an upvote, so that when the meta discussion is up you have enough rep to chime in as well. \$\endgroup\$ – Mathieu Guindon Nov 25 '19 at 23:50
  • \$\begingroup\$ Meta discussion about the tag: codereview.meta.stackexchange.com/q/9414/23788 \$\endgroup\$ – Mathieu Guindon Nov 26 '19 at 0:14
  • \$\begingroup\$ As the meta discussion is currently making a rather solid case for GraphQL schema to be off-topic if presented without any code to consume it, I'll be putting this question on hold so that it can be freely edited without interference from potential answers. \$\endgroup\$ – Mathieu Guindon Nov 26 '19 at 16:39

Browse other questions tagged or ask your own question.