Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-graphql-js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-graphql-js

GraphQL Schema to GraphQL.js Babel Plugin

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

GraphQL Schema to GraphQL.js Plugin

Circle CI

Babel plugin that uses a tagged template string with two expressions, the first being the string of the GraphQL Schema Language. The second being a decorator object to apply resolvers, descriptions and deprecations.

##Tagged Template String

graphql`${"schema"} ${decorator}`

###Example

const StarWarsTypes = graphql`${`

enum Episode { NEWHOPE, EMPIRE, JEDI }

interface Character {
  id: String!
  name: String
  friends: [Character]
  appearsIn: [Episode]
}

type Human implements Character {
  id: String!
  name: String
  friends: [Character]
  appearsIn: [Episode]
  homePlanet: String
}

type Droid implements Character {
  id: String!
  name: String
  friends: [Character]
  appearsIn: [Episode]
  primaryFunction: String
}

type Query {
  hero(episode: Episode): Character
  human(id: String!): Human
  droid(id: String!): Droid
}
`}${
{
  Character: {
    description: 'A character in the Star Wars Trilogy',
    resolveType: () => { return StarWarsSchema.Human; },
    id: {
      description: 'The id of the character.'
    }
  },
  Droid: {
    description: 'A mechanical creature in the Star Wars universe.'
    name: {
      resolve: () => { return 'Buzz Droid'; }
    }
  }
}
}`;

Using https://github.com/graphql/express-graphql you can then easily setup your GraphQL endpoint.

export var StarWarsSchema = new GraphQLSchema({
  query: StarWarsTypes.Query
});

const app = express();
app.use('/', graphqlHTTP({ schema: StarWarsSchema, graphiql: true }));

const server = app.listen(3000, function () {
  const host = server.address().address;
  const port = server.address().port;
  console.log('Example app listening at http://%s:%s', host, port);
})

FAQs

Package last updated on 23 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc