Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ad-hoc / custom GraphQL resolvers and definitions (schemas) #508

Closed
1 of 5 tasks
thescientist13 opened this issue Apr 4, 2021 · 0 comments · Fixed by #509
Closed
1 of 5 tasks

support ad-hoc / custom GraphQL resolvers and definitions (schemas) #508

thescientist13 opened this issue Apr 4, 2021 · 0 comments · Fixed by #509
Assignees
Labels
Content as Data enhancement Improve something existing (e.g. no docs, new APIs, etc) v0.12.0
Milestone

Comments

@thescientist13
Copy link
Member

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

In some discussions with @hutchgrant and exploring use cases around #21 , there is a case to be made that you could use GraphQL for not specifically tied to the graph specifically. For external content sure, that would need to go into the graph, but anything not content, like the config, might want to establish its own top level schema. But maybe there could be some overlap?

For example, for image galleries (as was the use case being discussed) your data source there would just be a set of images, either from a directory or cloud host.

Details

So basically this would require a convention / API for plugin-graphql to be able to scan for schemas in a repo and merge those into the overall schema. Similar to NextJS or Netlify, something like

// src/data/schema.js in a user's workspace
const gql = require('graphql-tag');

const getGallery = async (root, query, context) => {
  return [{
    name: 'Gallery 1',
    title: 'Gallery Title',
    images: [{
      path: '/assets/gallery1/image1.png'
    }, {
      path: '/assets/gallery1/image2.png'
    }]
  }];
};

const galleryTypeDefs = gql`
  type Image {
    path: String
  }

  type Gallery {
    name: String,
    title: String,
    images: [Image]
  }

  extend type Query {
    gallery: [Gallery]
  }
`;

const galleryResolvers = {
  Query: {
    gallery: getGallery
  }
};

module.exports = {
  customTypeDefs: galleryTypeDefs,
  customResolvers: galleryResolvers
};

You could then query it with your own .gql

query {
  gallery {
    name,
    title,
    images {
      path
    }
  }
}
@thescientist13 thescientist13 added enhancement Improve something existing (e.g. no docs, new APIs, etc) Content as Data labels Apr 4, 2021
@thescientist13 thescientist13 added this to the 1.0 milestone Apr 4, 2021
@thescientist13 thescientist13 self-assigned this Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content as Data enhancement Improve something existing (e.g. no docs, new APIs, etc) v0.12.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant