TypeError: Failed to fetch

This error does not give much helpful information to debug.

{
  "message": "Failed to fetch",
  "stack": "TypeError: Failed to fetch"
}

We created a type on Slash and ran a mutation and loaded 29K nodes (I think, still can’t count nodes in graphql) Then we found some data problems and need to drop the data in that type and rerun the import mutation.

mutation {
  deleteMyType(filter: {}) { numUids }
}

which resulted in the response above.

I modified the type to add an index on string field that has mostly the same value to get rid of a big chunk of the data with @search(by: [exact]) and then ran the following mutation:

mutation {
  deleteMyType(filter: {post_status: {eq: "Posted"}}) { numUids }
}

and this resulted with the same response above.

Is there any other way to data in a type when something in there is corrupting the delete mutation from running?

FYI, we have modified the schema back and forth several times for this type.

Thinking I may have to run some DQL to just delete by dgraph.type upsert mutation

trying to fire off DQL upsert block to delete the data using my slash endpoint.

upsert {
  query {
    v as var(func: eq(dgraph.type, "MyType"))
  }
  mutation {
    delete {
      uid(v) * * .
    }
  }
}

Apparently:

  • The /query endpoint does not support upserts
{
  "errors": [
    {
      "message": "while lexing upsert {\n\tquery {\n\t  v as var(func: eq(dgraph.type, \"MyType\"))\n  }\n  mutation {\n\t\tdelete {\n\t\t  uid(v) * * .\n\t  }\n\t}\n} at line 1 column 0: Invalid operation type: upsert",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ],
  "data": null
}
  • The /mutate endpoint does not support application/graphql+- Content-type
{
  "errors": [
    {
      "message": "Unsupported Content-Type. Supported content types are application/json, application/rdf",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

To run a GraphQL+- upsert, you’d use the /mutate endpoint and use the content type application/rdf for the upsert with RDF-syntax like uid(v) * *.

Yes, I believe @dmai is correct. Relevant docs here: https://dgraph.io/docs/master/mutations/conditional-upsert/.

If you saw a “failed to fetch” could you check if you got any logs in your browser console? The most common reason for things not being fetched is for that for whatever reason, you got an HTTP error, and CORS headers weren’t present on that error. Likely, the network tab / console of your browser will have the error code for us to debug further.

1 Like

Access to fetch at 'https://[super-secret].us-west-2.aws.cloud.dgraph.io/graphql' from origin 'https://slash.dgraph.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Of course I switched out super-secret

Request Headers: (left out :authority: which has my url in it.)

Thank you @dmai, That worked to run the upsert.

I am still not that good with DQL syntax. I got a completion success done status from my upsert but the data is still there. Can you help me with a upsert to delete all data of a type?

@gja, With graphql I can delete a few at once with a filter using id but if I try to use a filter that selects a larger amount of data then the delete errors out. Almost like it is timing out or that it cannot process because it is too many uids trying to delete at once.