Similar question, totally new to graphql and apoll...
# prisma-whats-new
d
Similar question, totally new to graphql and apollo How can I access single user by i.e. email model
Copy code
type User @model {
  id: ID! @isUnique
  name: String
  email: String! @isUnique
  number: String
}
query code
Copy code
const getUserQuery = gql`
query User($email: String!) {
  User(email: $email){
    id
    name
  }
}
`;

checkProfileSubscription: Subscription
myemail:String = ‘exampleEmail@mail.com'

this.checkProfileSubscription = this.apollo.watchQuery({
      query: getUserQuery,
      variables: {
        $email: this.myemail
      }
    }).subscribe(({data}: any) => {
      console.log(data)
    });
I get error like
Error:  GraphQL error: Variable '$email' expected value of type 'String!' but value is undefined. Reason: Expected non-null value, found null. (line 1, column 12): query User($email: String!)
n
you need to add
@isUnique
to the email field
d
but it is there in the schema? or should I add it elsewhere as well? I doesn't work when I test with predefined $id as well 😕 @nilan
it seems like vars are not passed by apollo properly as this change directly in the query works
Copy code
const getUserQuery = gql`
query User {
  User(email: "<mailto:userEmail@mail.com|userEmail@mail.com>"){
    id
    name
  }
}
`;
n
Expected non-null value, found null.
this
is probably not what you think it is
$email: this.myemail
d
huh, even when I enter string directly there it does not pick up in variables part of the apollo function
n
ohh
you need to say
variables : { email: "email" }
no
$
in the JavaScript object
only in the GraphQL document
d
oh, ffs 😂 thanks! @nilan you rock, wasn't aware of that at all 👏