Giter Club home page Giter Club logo

gatsby-source-figma's Introduction

gatsby-source-figma

PRs Welcome npm

Gatsby plugin for using Figma documents as a data source.

Screenshot

Installation

yarn add gatsby-source-figma

Usage

// In your gatsby-config.js

plugins: [
  {
    resolve: `gatsby-source-figma`,
    options: {
      // For files:
      fileId: `FIGMA_FILE_ID`,
      // For images:
      nodeIds: [`FIGMA_NODE_IDS`],
      // optional for nodeIds: A number between 0.01 and 4, the image scaling factor
      scale: 1,
      // optional: A string enum for the image output format, can be jpg, png, svg, or pdf
      format: 'png'
      // For projects:
      projectId: `FIGMA_PROJECT_ID`,
      // Get an access token from Figma Account Settings.
      accessToken: `YOUR_FIGMA_ACCESS_TOKEN`,
    },
  },
],

For all requests, you must have an accessToken. You can create an access token inside your Figma settings.

To access a file, also pass a fileId.

To get screenshots, also pass in a fileId, nodeIds. Additionally, you can pass in scale (number) and/or format (png, jpg, svg, pdf), but they're not required.

To get a project, pass in a projectId.

Querying

Files

Make sure that fileId and accessToken are set inside gatsby-config.js.

query StyleguideQuery {
  figmaDocument {
    name
    lastModified
    thumbnailUrl
    pages {
      name
      children {
        name
      }
    }
  }
}

Images (Artboards, also known as nodes)

Make sure that fileId, nodeIds, and accessToken are set inside gatsby-config.js. You can also set scale and format.

The node Id and file key can be parsed from any Figma node url: (https://www.figma.com/file/:key/:title?node-id=:id).

query ImageQuery {
  allFigmaImage {
    nodes {
      id
      image
    }
  }
}

Projects

Make sure that projectId and accessToken are set inside gatsby-config.js. Using this method, you can now query components, frames, instances, and more via graphql filters.

// All Figma Documents

query ProjectQuery {
  allFigmaDocument {
    edges {
      node {
        name
        pages {
          name
        }
      }
    }
  }
}
// Specific Figma Component

query ProjectComponentQuery {
  figmaComponent(name: {eq: "MyComponent"}) {
    instances {
      name
      rectangles {
        name
      }
      texts {
        name
      }
    }
  }
}
// Figma Frames that start with "Button"

query ProjectFrameQuery {
  allFigmaFrame(filter: {name: {regex: "/Button/"}}) {
    edges {
      node {
        name
      }
    }
  }
}

Use the built-in GraphiQL tool (http://localhost:8000/___graphql) to get an idea of what you can query.

Todo

  • Query files.
  • Query multiple files.
  • Query one or multiple file images.
  • Query projects.
  • Query file comments.

Authors

gatsby-source-figma's People

Contributors

brandonwkipp avatar fabe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gatsby-source-figma's Issues

Query projects

Currently, it's only possible to query a single file. It should also be possible to query a project with multiple files. We can then make use of allFigmaDocument.

Instead of options.fileId, allow options.projectId.

Error: Type with name "FigmaELLIPSE" does not exists

Receive the following error when trying to build Gatsby

Missing onError handler for invocation 'building-schema', error was 'Error: Type with name "FigmaELLIPSE" does not exists'. 
Stacktrace was 'Error: Type with name "FigmaELLIPSE" does not exists
  at SchemaComposer.get (/gatsby/node_modules/graphql-compose/lib/TypeStorage.js:44:13)
  at TypeMapper.get (/gatsby/node_modules/graphql-compose/lib/TypeMapper.js:86:44)
  at TypeMapper.typeFromAST (/gatsby/node_modules/graphql-compose/lib/TypeMapper.js:608:17)
  at TypeMapper.typeFromAST (/gatsby/node_modules/graphql-compose/lib/TypeMapper.js:603:24)
  at TypeMapper.typeFromAST (/gatsby/node_modules/graphql-compose/lib/TypeMapper.js:598:24)
  at TypeMapper.getWrapped (/gatsby/node_modules/graphql-compose/lib/TypeMapper.js:105:17)
  at TypeMapper.convertOutputFieldConfig (/gatsby/node_modules/graphql-compose/lib/TypeMapper.js:272:114)
  at resolveOutputConfigAsThunk (/gatsby/node_modules/graphql-compose/lib/utils/configAsThunk.js:19:41)
  at ObjectTypeComposer.getFieldConfig (/gatsby/node_modules/graphql-compose/lib/ObjectTypeComposer.js:300:58)
  at /gatsby/node_modules/graphql-compose/lib/utils/toInputObjectType.js:44:19
  at Array.forEach (<anonymous>)
  at toInputObjectType (/gatsby/node_modules/graphql-compose/lib/utils/toInputObjectType.js:38:14)
  at ObjectTypeComposer.getInputTypeComposer (/gatsby/node_modules/graphql-compose/lib/ObjectTypeComposer.js:600:84)
  at getSortInput (/gatsby/node_modules/gatsby/src/schema/types/sort.ts:152:42)
  at addTypeToRootQuery (/gatsby/node_modules/gatsby/src/schema/schema.js:1133:23)
  at processTypeComposer (/gatsby/node_modules/gatsby/src/schema/schema.js:216:13)'

Query comments

This is less important I'm assuming, but it might be nice to be able to query comments from a Figma file.

Query pages/layers/children

It should be possible to query by page or layer name etc. via arguments. For example:

query StyleguideQuery {
  figmaDocument {
    pages(name: { eq: "Colors" }) {
      name
      children {
        name
      }
    }
  }
}

Can't get it running

Hello,

This looks super helpful. I'm trying to get it going.

I created something from scratch using: gatsby new reactTest
Then I edited the config.js and added:

  • my access token, and for the file ID,
  • for the id from the Figma URL I get when I open the sketch in the browser: TV9yeRhO....

When I run the example from the documentation:

module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
  {
    resolve: `gatsby-source-figma`,
    options: {
      // For files:
      //fileId: `TV9yeRhO....`,
      // For projects:
      projectId: `TV9yeRhO....`,
      // Get an access token from Figma Account Settings.
      accessToken: `XXXXX-XXXX0137-6a01-4b4a-a85c-04b5ac88d0d7`,
    },
  },
],
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
}

I get this error:

{
  "errors": [
    {
      "message": "Cannot query field \"allFigmaDocument\" on type \"Query\".",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "stack": [
        "GraphQLError: Cannot query field \"allFigmaDocument\" on type \"Query\".",
        "    at Object.Field (C:\\reactTest2\\node_modules\\graphql\\validation\\rules\\FieldsOnCorrectType.js:64:31)",
        "    at Object.enter (C:\\reactTest2\\node_modules\\graphql\\language\\visitor.js:334:29)",
        "    at Object.enter (C:\\reactTest2\\node_modules\\graphql\\language\\visitor.js:385:25)",
        "    at visit (C:\\reactTest2\\node_modules\\graphql\\language\\visitor.js:252:26)",
        "    at validate (C:\\reactTest2\\node_modules\\graphql\\validation\\validate.js:63:22)",
        "    at C:\\reactTest2\\node_modules\\express-graphql\\dist\\index.js:154:52",
        "    at process._tickCallback (internal/process/next_tick.js:68:7)"
      ]
    }
  ]
}

Any idea how to fix that?
Could it be due to the fact that I installed gatsby-source-figma via yarn, but my gatsby prefers npm as package manager?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.