0

Im using Prisma, Apollo and React. Ive added a picture field to Users which shows up fine in the Prisma playground but in React it always comes back null, but if I query other fields its fine. Im really confused why this isn't working, have I made a syntax error?

datamodel.graphql:

type User {
  id: ID! @unique
  picture: String
}

schema.graphql:

type User {
  id: ID!
  picture: String
}

type Query {
  user(id: ID!): User
}

My resolver:

  async user(parent, args, ctx, info) {
    const { id } = args;
    const result = await ctx.db.query.user({ where: { id } }, info);
    return result;
  },

React component:

export const USER_QUERY = gql`
  query UserQuery($userId: ID!) {
    user(id: $userId) {
      id
      picture
    }
  }
`;

export default compose(
  graphql(USER_QUERY, {
    name: 'USER_QUERY',
    options: props => {
      return {
        variables: {
          userId: 'cjgylfv6y004h0958tx9d8j9v',
        },
      };
    },
  }),
)(UserPic);

1 Answer 1

0

Just a shot in the dark.

I see you have fixed user id cjgylfv6y004h0958tx9d8j9v in your code. If that user was inserted before deploying your changes to Prisma, it would have a null value for the attribute picture.

Try with a query that lists all your users.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.