Prisma1: Cannot return null for non-nullable field Organization.id

Created on 16 Apr 2019  路  3Comments  路  Source: prisma/prisma1

I am experiencing this issue after upgrading from Prisma 1.29.1 to Prisma 1.30.1
Shows this on Queries and Mutations, even when they are successful.

Here's my graphql query and mutation:

Mutation:

mutation createOrganization($args: OrganizationCreateInput!) {
    createOrganization(data: $args) {
      id
    }
  }

Query:

query getViewerOrganization {
        getViewerOrganization {
            id
        }
    }

Here's my datamodel:

type Organization {
    id: ID! @unique
    name: String!
    .......
}

Here's my Schema:

type Mutation {
      createOrganization(data: OrganizationCreateInput!): Organization!
}

type Query {
      getViewerOrganization(data: OrganizationWhereInput): Organization
}

type Viewer {
    me: User!
}

Here's my resolvers:

Mutation

// @ts-ignore
export const createOrganization = async (args, context) => {

    try {

        const id = getUserId(context);
        const user = await context.db.user({id});

        ...........

        const organization = await context.db.createOrganization({
            ...args.data,
            owner: {
                connect: {
                    id
                }
            },
            users: {
                connect: [
                    {email: user.email}
                ]
            }
        });

        return {
             organization
        }

    } catch (e) {
        return new ApolloError(e.message);
    }

};

Query:

// @ts-ignore
  getViewerOrganization: async (parent, args, context) => {

    try {

      const id = await getUserId(context);
      const user = await context.db.user({id});
      const organization = await context.db.organization({id});

      return {
        organization
      }

    } catch (e) {
      return new ApolloError(e.message);
    }

  },
  • Connector:MySQL
  • Prisma Server: 1.30.1
  • prisma CLI: prisma/1.30.1
  • OS: Windows 10

What could be the issue?

bu0-needs-info areclient

Most helpful comment

Sorry should not you replace
return { organization }

by return organizatoin

All 3 comments

Can you please add a console.log and see what the organization object contains?

Also, with the provided information, I am unable to reproduce this issue. If you are still getting this, can you please make a small repository with a minimal reproduction.

Sorry should not you replace
return { organization }

by return organizatoin

I was able to fix it by using

return {...organization}
or
return organization

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tbrannam picture tbrannam  路  3Comments

schickling picture schickling  路  3Comments

schickling picture schickling  路  3Comments

marktani picture marktani  路  3Comments

jannone picture jannone  路  3Comments