Search code examples
graphqlapolloapollo-server

Is there a dataset for GraphQL?


I'm playing with Apollo/GraphQL on a neo4j DB

In Neo4j there is the 'Movies & Persons' Dataset

Is there something similar for GraphQL (ie Schema, Data, Queries, Mutations, ...) which I could use to play around in my demo app / connected to apollo studio sandbox explorer?


Solution

  • It is possible to generate a schema for data on neo4j

    import { toGraphQLTypeDefs } from "@neo4j/introspector";
    import neo4j from "neo4j-driver";
    import fs from 'fs';
    
    const AURA_ENDPOINT = 'bolt://localhost:7687';
    const USERNAME = 'neo4j';
    const PASSWORD = 'pass';
    
    
    const driver = neo4j.driver(
        AURA_ENDPOINT,
        neo4j.auth.basic(USERNAME, PASSWORD)
    );
    
    const sessionFactory = () => driver.session({ defaultAccessMode: neo4j.session.READ })
    
    // We create a async function here until "top level await" has landed
    // so we can use async/await
    async function main() {
        const typeDefs = await toGraphQLTypeDefs(sessionFactory)
        fs.writeFileSync('schema.graphql', typeDefs)
        await driver.close();
    }
    main()
    
    

    adapted from here

    the output can be used as typedef

    
    const typeDefs = gql`
      interface ActedInProperties @relationshipProperties {
        roles: [String]!
    }
    
    type Movie {
        peopleActedIn: [Person!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedInProperties")
        peopleDirected: [Person!]! @relationship(type: "DIRECTED", direction: IN)
        peopleProduced: [Person!]! @relationship(type: "PRODUCED", direction: IN)
        peopleReviewed: [Person!]! @relationship(type: "REVIEWED", direction: IN, properties: "ReviewedProperties")
        peopleWrote: [Person!]! @relationship(type: "WROTE", direction: IN)
        released: BigInt!
        tagline: String
        title: String!
    }
    
    type Person {
        actedInMovies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedInProperties")
        born: BigInt
        directedMovies: [Movie!]! @relationship(type: "DIRECTED", direction: OUT)
        followsPeople: [Person!]! @relationship(type: "FOLLOWS", direction: OUT)
        name: String
        peopleFollows: [Person!]! @relationship(type: "FOLLOWS", direction: IN)
        producedMovies: [Movie!]! @relationship(type: "PRODUCED", direction: OUT)
        reviewedMovies: [Movie!]! @relationship(type: "REVIEWED", direction: OUT, properties: "ReviewedProperties")
        wroteMovies: [Movie!]! @relationship(type: "WROTE", direction: OUT)
    }
    `;