4. Follow-along: Debugging Connectors
1m

Follow-along: Debugging Connectors

You can use the Connectors Debugger to dig deeper into the details of your Connector network requests. Let's try adding a that doesn't exist in the REST API response.

  1. Add a url to the Product type.

    products.graphql
    type Product {
    id: ID!
    name: String
    description: String
    category: String
    url: String
    }
  2. Add url to the selection property of the Query.products Connector.

    products.graphql
    type Query {
    products: [Product]
    @connect(
    source: "ecomm"
    http: { GET: "/products" }
    selection: """
    $.products {
    id
    name
    description
    category
    url
    }
    """
    )
    }
  3. Save your changes. rover dev will restart.

  4. Go to http://localhost:4000 where the local is running. Add the url to the existing .

    GraphQL operation
    query GetProducts {
    products {
    id
    name
    description
    category
    url
    }
    }
  5. We'll get data back, but we'll also see a warning icon. Click on it to open the Connectors Debugger panel.

    Warning icon

  6. Click on the icon under Problems.

    Debugger problems

  7. The message shows the error Property.url not found in object. Click the code </> icon to open the Mapping Playground.

    Mapping error

Connectors Mapping Playground

Mapping playground

You can always use the playground to write and troubleshoot your Connector .

  • The REST API's JSON response body is on the left in the API Response panel
  • The Connector's mapping selection is in the center Mapping panel
  • The results of the mapping are in the right Results panel
  • When the errors are fixed and the results are what you expected, you can copy the mapping back into the selection property of the Connector in your schema

Fixing the selection

We want to take the slug value and map it to the url in the schema. We can rename fields with the syntax newName: oldName, much like in .

  1. In the mapping playground, edit the mapping to rename slug to url to remove errors.

    url: slug

    Mapping playground

    The error should go away!

  2. In the products.graphql file, find the selection property and do the same renaming url: slug

    products.graphql
    type Query {
    products: [Product]
    @connect(
    source: "ecomm"
    http: { GET: "/products" }
    selection: """
    $.products {
    id
    name
    description
    category
    url: slug
    }
    """
    )
    }
  3. Save your changes. rover dev will restart.

  4. Go to http://localhost:4000 and run the again. There should be no errors!

What would the correct selection syntax be if the JSON property is called name but the schema defines it as fullName?
Previous