braposo / figma-graphql

The reimagined Figma API (super)powered by GraphQL
https://figma-graphql.party
MIT License
395 stars 21 forks source link

Create a client library #28

Open braposo opened 5 years ago

braposo commented 5 years ago

This project at the moment is focused on providing a GraphQL service that connects to the Figma API and allows clients to query it through the GraphQL API.

However, I've been thinking lately that we're not doing much more than getting the API response, parsing it and returning the information required in the GraphQL query.

So maybe we could actually use something like graphql-anywhere and build a client-side library that provides a GraphQL interface to the Figma API.

I imagine something like:

import FigmaGQL from "figma-graphql";

const queryFigma = FigmaGQL.connect({
    personalAccessToken: token
});

const fileNameQuery = gql`
    {
        file(id: "cLp23bR627jcuNSoBGkhL04E") {
            name
        }
    }
`;

const result = queryFigma(fileNameQuery);
/*
{
    "file": {
        "name": "figma-graphql test file"
    }
}
*/

This would allow people to easily start querying the Figma API with GraphQL without having to worry about running the server.

For those that want more power and the benefits of a proper GraphQL implementation there would be a figma-graphql-server repository with this version of the code.

souporserious commented 5 years ago

@braposo have you looked into this any further? I'd love to help out here if possible. My GraphQL knowledge is somewhat limited since I've really only used it within Gatsby, but I'd be happy to try and get this at least started :)

braposo commented 5 years ago

hey @souporserious! I haven't really started anything yet, but I want to make this a priority soon, just haven't found the time to focus on it. I'm trying to get the existing (server) version "feature complete" first and then think about the client library.

I was thinking about taking a similar approach to what I did for https://github.com/braposo/graphql-css but the way graphql-anywhere works is a bit different and right now I'm not sure how to reuse the existing resolvers so it will probably need some analysis before committing to that approach.

I'm happy to get some help though so if you feel like it's something you'd like to spend some time with just let me know!

souporserious commented 5 years ago

Sounds good! I'll wait for the dust to settle with the server version. In the meantime, I'll tinker around and see if I can get a proof of concept together. Thanks!

braposo commented 5 years ago

That's great, let me know if you need anything from me! I'm going to try to have most of this sorted until the end of the month so I can start working on the client version in October but we'll see how that goes.