Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

Issue w/ auto Generated IDs #4

Open
eferrervaughn opened this issue Jul 12, 2018 · 2 comments
Open

Issue w/ auto Generated IDs #4

eferrervaughn opened this issue Jul 12, 2018 · 2 comments

Comments

@eferrervaughn
Copy link

The Error

Error: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "3hWjFg8z7faY" doesnt.

GraphQL does not like nodes that start with numbers. The library you based this off of has a way of doing it but could you just prepend a string "id" when you create the nodes.

here is how the other library attacks it

        // This allows you to map your data to data that GraphQL likes:
        // 1. Turn your lists into actual arrays
        // 2. Fix keys that GraphQL hates. It doesn't allow number keys
        //    like "0", you'll get this error pretty often:
        //    Error: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "0" does not
        // 3. Remove stuff you don't need.
        //
        // Feel free to mutate, we sent you a copy anyway.
        map: node => {
          // fix keys graphql hates
          node.nineteenEightyFive = node['1985']
          delete node['1985']

          // convert a child list to an array:
          return node.sessions = Object.keys(node.sessions).map(key => {
            return { _key: key, session: node.sessions[key] }
          })

          // finally, return the node
          return node
        },
      },
@eferrervaughn
Copy link
Author

@alvinthen @baymose Here is a similar error:
gatsbyjs/gatsby#3374

It seems my options are

  1. changing the id's of all my firestore records (not feasible and breaks one of firestores key features AutoID.
  2. Updating this part of the code to start each name with a character
    for (let doc of snapshot.docs) { const contentDigest = getDigest(doc.id); <--- here const node = createNode( Object.assign({}, map(doc.data()), { id: doc.id, <--- here parent: null, children: [], internal: { type, contentDigest, }, }) );

@alvinthen
Copy link
Member

I pushed a branch using your suggested method 2 here. Please try it out.

As of this moment, I'm hesitant to merge to master branch as it may cause breaking changes to those that's actually using hardcoded ID. Due to shortage of resources we can't look into this issue deeply. We're happy to accept PRs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants