Skip to content

Instantly share code, notes, and snippets.

@jexp
Created June 17, 2018 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jexp/7afbebf22b1aeacb2fee805b441fd081 to your computer and use it in GitHub Desktop.
Save jexp/7afbebf22b1aeacb2fee805b441fd081 to your computer and use it in GitHub Desktop.
grandstack-starter StackOverflow
NEO4J_URI=bolt://107.170.69.23:7687
NEO4J_USER=graphql
NEO4J_PASSWORD=graphql
GRAPHQL_URI=http://localhost:4000
import { neo4jgraphql } from "neo4j-graphql-js";
export const typeDefs = `
type Link {
url: ID!
}
type SOUser {
id: ID!
questions(first: Int = 10, offset: Int = 0): [Question] @relation(name:"POSTED", direction:"OUT")
answers(first: Int = 10, offset: Int = 0): [Answer] @relation(name:"POSTED", direction:"OUT")
reputation: Int
name: String
location: String
profile_image_url: String
}
type Tag {
name: ID!
tagged(first: Int = 10, offset: Int = 0): [Question] @relation(name:"TAGGED", direction:"IN")
}
type Question {
id: ID!
title: String
link: String
score: Int
text: String
closed_date: Int
closed_reason: String
favorites: Int
view_count: Int
comment_count: Int
is_answered: Boolean
created: Int
updated: Int
answers(first: Int = 10, offset: Int = 0): [Answer] @relation(name:"ANSWERED", direction:"IN")
author: SOUser @relation(name:"POSTED", direction:"IN")
tags: [Tag] @relation(name:"TAGGED", direction:"OUT")
}
type Answer {
id: ID!
text: String
comment_count: Int
is_accepted: Boolean
created: Int
score: Int
question: Question @relation(name:"ANSWERED", direction:"OUT")
author: SOUser @relation(name:"POSTED", direction:"IN")
}
type Query {
users(id: ID, name: String, first: Int = 10, offset: Int = 0): [SOUser]
## @cypher(statement:"MATCH (u:User:StackOverflow) RETURN u LIMIT $first+$offset SKIP $offset")
questions(id: ID, title: String, first: Int = 10, offset: Int = 0): [Question]
tag(name: ID!): Tag
}
`;
export const resolvers = {
Query: {
users: neo4jgraphql,
questions: neo4jgraphql,
tag: neo4jgraphql
}
};
import React from "react";
import { Query } from "react-apollo";
import gql from "graphql-tag";
import './UserList.css';
const UserList = () => (
<Query
query={gql`
{
users(first: 10) {
name
questions(first:3) { title, score, tags {name} }
}
}
`}
>
{({ loading, error, data }) => {
if (loading) return <p>Loading...</p>;
if (error) return <p>Error</p>;
return (
<div className="UserList">
<h1>Users:</h1>
<ul>
{data.users.map((u,i)=> (
<li key={i}>{u.name} <ul>{u.questions.map((q,i) => (<li key={i}>{q.title} ({q.score} {q.tags.map((t)=>t.name).join(", ")})</li>))}</ul></li>
))}
</ul>
</div>
);
}}
</Query>
);
export default UserList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment