Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore create mutation gives me "is not a valid Document" error #29

Closed
jonesnc opened this issue Dec 22, 2018 · 1 comment · Fixed by #31
Closed

Firestore create mutation gives me "is not a valid Document" error #29

jonesnc opened this issue Dec 22, 2018 · 1 comment · Fixed by #31
Labels
bug Something isn't working data-source

Comments

@jonesnc
Copy link
Contributor

jonesnc commented Dec 22, 2018

Describe the bug
My GraphQL Schema looks like this with FirebaseDataSource set up.

type User @GQLifyModel(dataSource: "firestore", key: "users") {
  id: ID! @unique @autoGen # auto generate unique id
  username: String!
  email: String
}

Here's my index.js file:

const { Gqlify } = require('@gqlify/server');
const { ApolloServer } = require('apollo-server');
const { readFileSync } = require('fs');
const { FirestoreDataSource } = require('@gqlify/firestore');
const cert = require('./gqlify-firebase-adminsdk-a22pq-f37440b45b.json');
const databaseUrl = 'https://gqlify.firebaseio.com';

// Read datamodel
const sdl = readFileSync(__dirname + '/demo.graphql', { encoding: 'utf8' });

// construct gqlify
const gqlify = new Gqlify({
    sdl,

    dataSources: {
        firestore: args => new FirestoreDataSource(cert, databaseUrl, args.key)
    }
});

// GQLify will provide GraphQL apis & resolvers to apollo-server
const server = new ApolloServer(gqlify.createApolloConfig());

// start server
server.listen().then(({ url }) => {
    console.log(`🚀 Server ready at ${url}`);
});

When I try to run a createUser migration with:

mutation {
  createUser(
    data: {
      username: "newuser",
      email: "email@example.com"
    }) {
      id
    }
}

Gives me this error:

{
  "data": {
    "createUser": null
  },
  "errors": [
    {
      "message": "Argument \"data\" is not a valid Document. obj.hasOwnProperty is not a function",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "createUser"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Argument \"data\" is not a valid Document. obj.hasOwnProperty is not a function",
            "    at Validator.(anonymous function).values [as isDocument] (/sandbox/node_modules/@google-cloud/firestore/build/src/validate.js:92:27)",
            "    at CollectionReference.add (/sandbox/node_modules/@google-cloud/firestore/build/src/reference.js:1680:25)",
            "    at FirestoreDataSource.<anonymous> (/sandbox/node_modules/@gqlify/firestore/lib/index.js:129:70)",
            "    at step (/sandbox/node_modules/@gqlify/firestore/lib/index.js:32:23)",
            "    at Object.next (/sandbox/node_modules/@gqlify/firestore/lib/index.js:13:53)",
            "    at /sandbox/node_modules/@gqlify/firestore/lib/index.js:7:71",
            "    at new Promise (<anonymous>)",
            "    at __awaiter (/sandbox/node_modules/@gqlify/firestore/lib/index.js:3:12)",
            "    at FirestoreDataSource.create (/sandbox/node_modules/@gqlify/firestore/lib/index.js:125:16)",
            "    at CreatePlugin.<anonymous> (/sandbox/node_modules/@gqlify/server/lib/plugins/create.js:137:55)"
          ]
        }
      }
    }
  ]
}

The obj.hasOwnProperty is not a function error may be due to graphql's usage of Object.create(null) when constructing args. See: graphql/express-graphql#177 (comment)

To Reproduce
Steps to reproduce the behavior:
2. Click on the Execute Query button in the GraphQL Playground window
3. See error

Expected behavior
A new users document to be created.

Versions:

"@gqlify/firestore": "^1.0.10",
"@gqlify/server": "^1.0.10",
"apollo-server": "^2.3.1"
jonesnc added a commit to jonesnc/gqlify that referenced this issue Dec 23, 2018
@wwwy3y3 wwwy3y3 added bug Something isn't working data-source labels Dec 23, 2018
@wwwy3y3
Copy link
Contributor

wwwy3y3 commented Dec 23, 2018

hi @jonesnc should be fixed at version v1.0.11.

btw, you should move the firestore secret in your sandbox by using their secret key feature.
screen shot 2018-12-23 at 3 51 16 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data-source
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants