1

I'm new to graphQL and was recently told to learn it. I'm trying to do a post request by registering an account but I get an error saying I need a subfield.

register user schema

Must have a selection of subfields

const getLoggedInUser = async req => {
  const token = req.headers["x-token"];
  if (token) {
    try {
      return await jwt.verify(token, process.env.JWT_SECRET);
    } catch (e) {
      throw new AuthenticationError(AUTHORISATION_MESSAGES.SESSION_EXPIRED);
    }
  }
};
Arthur Truong
  • 1,454
  • 3
  • 5
  • 13
  • Duplicate of [Field \"me\" of type \"User\" must have a selection of subfields](https://stackoverflow.com/questions/46111514/field-me-of-type-user-must-have-a-selection-of-subfields) – Daniel Rearden Dec 23 '18 at 14:48

1 Answers1

4

When you do the mutation, you must also request the payload. This payload is what the error recognizes you as "subfields".

In your case, i see that AccessToken has two subfields, token and user.

You must do the mutation in this way.

mutation {
  registerUser (
  firstName: "test",
  lastName: "test",
  password: "test",
  emailAddress: "test@gmail.com",
  type: "Patient"
  ) {
    token
    user
  }
}