nicolaslopezj / meteor-apollo-accounts

Meteor accounts in GraphQL
MIT License
146 stars 37 forks source link

How to define custom field in user.profile schema? #60

Closed joncursi closed 7 years ago

joncursi commented 7 years ago

Hi,

I am trying to create a custom user profile object through the createUser mutation.

createUser({
          email,
          password,
          profile: {
            gender: 'male',
            name,
          },
          username,
        }, apollo);

However I keep getting the error:

GraphQL error: Variable "$profile" got invalid value {"gender":"male","name":"Some Name"}.
In field "gender": Unknown field.

How do I register gender as a known field under profile? After digging around, I saw a lot of references to CreateUserProfileInput. Do I need to extend this in some way?

joncursi commented 7 years ago

Found some relevant information here (https://github.com/orionsoft/meteor-apollo-accounts/issues/52#issuecomment-299327917), seems like I'm not the only one stumbling on this aspect of the package.

After defining:

input CreateUserProfileInput {
  # The user's birthday
  birthday: Date
  # The user's gender information
  gender: UserGender
  # The user's full name
  name: String!
}

type UserGender {
  # The user's gender
  gender: String,
  # The user's gender identity
  identity: String,
  # The gender pronoun the user prefers
  pronoun: String,
}

Now getting:

Expected CreateUserProfileInput to be a GraphQL output type.

Investigating...

joncursi commented 7 years ago

This seems to fix it, for those looking to take control of the User schema:

type User {
  # The user's unique ID
  _id: ID!
  # The user's primary email address
  email: String!
  # A list of the user's email addresses
  emails: [UserEmail]
  # The user's profile information
  # profile: CreateUserProfileInput
}

type UserEmail {
  # The user's email address
  address: String!
  # Whether or not the user's email address has been verified
  verified: Boolean!
}

input CreateUserProfileInput {
  # The user's birthday
  birthday: Date
  # The user's gender information
  gender: UserGender
  # The user's full name
  name: String!
}

input UserGender {
  # The user's gender
  gender: String,
  # The user's gender identity
  identity: String,
  # The gender pronoun the user prefers
  pronoun: String,
}