1
votes

I'm using backend node server with the Apollo graphql (Server side) and on the client, I'm using Apollo Client as well.
I created a few client specific types in my client Schema for Apollo client but I'm wondering:
Should I do the same for backend Types (models)? Just to add some sanity, etc.

Let me explain it a bit detailed with an example:

Here is the client schema: (Client specific types)

import gql from 'graphql-tag';

export default gql`
  type System {
    showSignInModal: Boolean!
  }

  type Robot {
    name: String!
    status: String!
  }

  type Member {
    name: String!
    isLogged: Boolean!
  }

  type Author {
    id: Int!
    posts: Int!
    name: String
  }


  input AuthorInput {
    id: Int!
    posts: Int!
    name: String
  }

`;

I have a query that fetches the user data from the server (Server specific data)
so should I describe the whole User type in my schema as well?

import gql from "graphql-tag";

export const GET_USER_SHORT_DATA = gql`
  mutation getUserShortData {
    me {
      id,
      email,
      name,
      profileUrl,
      locale
    }
  }
`;

Thanks for any advice!

1

1 Answers

0
votes

I assume you're using mongoose for your database operations. Your main types should be defined in your mongoose schema as GraphQL is just a query language meant for "getting only what you want". So, you should add the same types in both the places. In your mongoose code for database handling & In your GraphQL Schema for query fetch support.

For Client side, if you're using a typed language like typescript, then you should define them in the client side too so as to prevent bugs & get better IDE suggestions.