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.

Question about /data/graphql/Database/* quotes on feature/apollo

See original GitHub issue

Hi all,

On the branch feature/apollo I can see in the folder /data/graphql/Database/* some files with code quoted with backticks, like in https://github.com/kriasoft/react-starter-kit/blob/feature/apollo/src/data/graphql/Database/users/CreateUser.js#L4.

My question is if this is about Apollo or about Graphql, and what do they mean.

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
langpavelcommented, Apr 6, 2018

Ughh this.props.dataForComponent.data.databaseGetUser souds really crazy. You can use something like this.props.user in component, go for it! 🙂 It’s real and you can unlock new level, please keep discovering 🙂

0reactions
ghostcommented, Apr 2, 2018

@langpavel Ok, I think I got the idea. I just managed to retrieve the parameter on the url with this:

Lets say I have this route for a component oneUser:

   {
     path: '/oneuser/:id',
     load: () => import(/* webpackChunkName: 'oneUser' */ './oneUser'),
   },

Then in the component, in index.js:

import React from 'react';
import OneUser from './OneUser';
import oneUserQuery from './OneUser.graphql';
import Layout from '../../components/Layout';

async function action({ client, params }) {

  const data = await client.query({
    query: oneUserQuery,
    variables: { id: params.id },
  });
  return {
    title: 'React Starter Kit',
    chunks: ['oneUser'],
    component: (
      <Layout>
        <OneUser dataForComponent={data} />
      </Layout>
    ),
  };
}

export default action;

The query in OneUser.graphql will be:

query OneUser($id: Int) {
  databaseGetUser(id: $id) {
    id
    email
  }
}

And in oneUser.js:

import React from 'react';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './OneUser.css';

class OneUser extends React.Component {
  render() {
    const { id, email } = this.props.dataForComponent.data.databaseGetUser;

    return (
      <div className={s.root}>
        <div>
          <h1>This is one thing</h1>
          <article key="a">
            <h1>{id}</h1>
            <p>{email}</p>
          </article>
        </div>
      </div>
    );
  }
}

export default withStyles(s)(OneUser);

I just had to modify the databaseGetUser query to search by id instead by email.

It works, but… is this.props.dataForComponent.data.databaseGetUser a proper way to retrieve data from index.js?

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL query best practices
When creating queries and mutations, follow these best practices to get the most out of both GraphQL and Apollo tooling. Name all operations....
Read more >
Graphql instead of custom data engine · Discussion #315
This is just me daydreaming: The backend could use the graphql schema to generate the database schema as well as queries/mutations for all...
Read more >
GraphQL specification
GraphQL describes the types of data expected by query variables. Input types may be lists of another input type, or a non‐null variant...
Read more >
Building a GraphQL Application with Vue 3 and Apollo
This data graph centralizes all of the APIs consumed by your application by mapping each field to a resolver that populates it with...
Read more >
Getting up and running with GraphQL
GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they...
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