Explain this break down in my schema

Schema:

type User {
    id:            ID!                      
    userID:        String!                  @search(by: [exact, regexp])
    firstName:     String!                  @search(by: [term, regexp])
    lastName:      String!                  @search(by: [term, regexp])
    email:         String!                  @search(by: [term, regexp])
    username:      String!                  @id
    avatar:        String                   
    displayName:   String!                  @search(by: [term, regexp])
    prefix:        String                   
    suffix:        String                   
    phone:         String                   
    city:          City                     
    birthday:      DateTime                 
    tagline:       String                   
    bio:           String                   
    homepage:      String                   
}

type City {
    id:            ID!                      
    name:          String!                  
    state:         State                    
}

type State {
    name:          String!                  @id
    cities:        [City]                   
}

I created a city in state during an updateUser mutation… It looked like this:

mutation UpdateUser($userID: String, $firstName: String, $lastName: String, $city: String, $state: String, $email: String, $avatar: String, $displayName: String, $prefix: String, $suffix: String, $phone: String, $birthday: DateTime, $tagline: String, $bio: String, $homepage: String) {
    updateUser(input: {filter: {userID: {eq: $userID}}, set: {
        firstName: $firstName,
        lastName: $lastName,
        email: $email,
        avatar: $avatar,
        displayName: $displayName,
        prefix: $prefix,
        suffix: $suffix,
        phone: $phone,
        city: {
          name: $city
          state: {
            name: $state
          }
        }
        birthday: $birthday,
        tagline: $tagline,
        bio: $bio,
        homepage: $homepage}}) {
        user {
            id
            userID
            firstName
            lastName
            email
            username
            avatar
            displayName
            prefix
            suffix
            phone
            birthday
            tagline
            bio
						homepage
          city {
            name
            state {
              name
            }
          }
        }
  }}

If I run this query on cities:

query GetCities {
  queryCity {
    id
    name
    state {
      name
    }
  }
}

I get a city with it’s state back… all good:

{
  "data": {
    "queryCity": [
      {
        "id": "0x2716",
        "name": "Jacksonville",
        "state": {
          "name": "Florida"
        }
      }
    ]
  },

But… if I do a similar query against the state… no cities…

query {
  getState(name: "Florida") {
    name
    cities {
      name
    }
  }
}

I get:

{
  "data": {
    "getState": {
      "name": "Florida",
      "cities": []
    }
  },

I am expecting for “Jacksonville” to be in the list of cities from “Florida”. Why am I not getting the edge that I’m expecting?

Never mind… I forgot to add @hasInverse(field: state)

Working fine now.

1 Like