question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation error on Schema basics topic

See original GitHub issue

In the schema basics topic we defined the next schema structure:

const typeDefs = gql`
  type Book {
    title: String
    author: Author
  }

  type Author {
    name: String
    books: [Book]
  }

  type Query {
    getBooks: [Book]
    getAuthors: [Author]
  }

  type Mutation {
    addBook(title: String, author: String): Book
  }
`;

But, with that structure and this data (provided by the documentation):

const books = [
  {
    title: 'Harry Potter and the Chamber of Secrets',
    author: 'J.K. Rowling',
  },
  {
    title: 'Jurassic Park',
    author: 'Michael Crichton',
  },
];

Is not possible to obtain the data as the documentation displays.

Doc result:

{
  "data": {
    "getBooks": [
      {
        "title": "Jurassic Park",
        "author": {
          "name": "Michael Crichton"
        }
      },
      ...
    ]
  }
}

My result:

{
  "data": {
    "getBooks": [
      {
        "title": "Harry Potter and the Chamber of Secrets",
        "author": {
          "name": null
        }
      },
      {
        "title": "Jurassic Park",
        "author": {
          "name": null
        }
      }
    ]
  }
}

am I doing something wrong or is it a doc error?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nikhilunni511commented, Mar 18, 2020

@enbermudas Hope you are mixing the contents from getting-started and schema-basics. My suggestion is if you follow the getting-started first, then you can solve the issue yourself. FYI, const books = [ { title: 'Harry Potter and the Chamber of Secrets', author: 'J.K. Rowling', }, { title: 'Jurassic Park', author: 'Michael Crichton', }, ]; this is from getting-started, but it won’t work with queries that you have mentioned in this issue. This data is not enough to work with your problem, you need to add some more data to work with your problem.

@abernix @enbermudas Please excuse me if I’m wrong.

1reaction
nikhilunni511commented, Mar 19, 2020

That’s what I’m talking about: there is code missing and there is no explanation on how to generate that code between those to tutorials. I’m lost.

@enbermudas Understood. But the getting-started is an overall idea about how to develop a server (create a project) and the schema-basics is just schema basics, so if you want to define data for the schema do it yourself, because we can do it in different ways. So that decision is always up to you. And I hope once you covered all the topics you will get the answer for your question. Now let me show you a few examples: example 1

const books = [
  {
    title: 'Harry Potter and the Chamber of Secrets',
    author: {
           name: 'J.K. Rowling'
      }
  },
  {
    title: 'Jurassic Park',
    author: {
           name: 'Michael Crichton'
     }
  },
];

example 1

const books = [
  {
    authorId: 1
    title: 'Harry Potter and the Chamber of Secrets',
  },
  {
    authorId: 2
    title: 'Jurassic Park',
  },
];
const authors = [
  {
    id: 1
    name: 'J.K. Rowling',
  },
  {
    id: 2
    name: 'Michael Crichton',
  },
];

We can define data for the schema in different ways as I stated above. Hope this will help you. Correct me if I’m wrong

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding schema errors | HESA
What is a schema error? The schema describes the structure of the XML document (number of elements, whether an element can be empty,...
Read more >
Manage Schemas for Topics in Control Center
Review the step-by-step tutorial for using Schema Registry. For comprehensive information on Schema Registry, see the Schema Registry documentation. The Schema ...
Read more >
Handling operation errors - Apollo GraphQL Docs
Validation errors (e.g., a query included a schema field that doesn't exist); Resolver errors (e.g., an error occurred while attempting to populate a...
Read more >
Step 5: Response example and schema (API reference tutorial)
The response schema documents the response in a more comprehensive, general way, listing each property that could possibly be returned, what ...
Read more >
Errors occurred while compiling the XML schemas in the project
To correct this error · Double-click the warning in the Errors List window. · Ensure that all required XSD schema (. · If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found