All Projects → aerogear → graphql-metadata

aerogear / graphql-metadata

Licence: MIT license
Annotate your graphql schema with lightweight directives

Programming Languages

typescript
32286 projects
shell
77523 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to graphql-metadata

Graphql Typescript
Define and build GraphQL Schemas using typed classes
Stars: ✭ 67 (+139.29%)
Mutual labels:  annotations, graphql-schema
accelerator-core-js
Accelerator Core provides a simple way to integrate real-time audio/video into your web application using the OpenTok Platform
Stars: ✭ 24 (-14.29%)
Mutual labels:  annotations
graphql-cli-load
A graphql-cli data import plugin to call mutations with data from JSON/CSV files
Stars: ✭ 63 (+125%)
Mutual labels:  graphql-schema
Parceler
简单的Bundle数据注入框架
Stars: ✭ 107 (+282.14%)
Mutual labels:  annotations
amigo
AmiGO is the public interface for the Gene Ontology.
Stars: ✭ 26 (-7.14%)
Mutual labels:  annotations
graphql-express-nodejs
A Simple GraphQL Server implementation using Express and Node. See post here: https://t.co/Cm6GitZaBL
Stars: ✭ 24 (-14.29%)
Mutual labels:  graphql-schema
GdprBundle
A symfony3 bundle to assist with defining data in accordance with GDPR, and for encrypting and reporting.
Stars: ✭ 61 (+117.86%)
Mutual labels:  annotations
AnnotationInject
Compile-time Swift dependency injection annotations
Stars: ✭ 40 (+42.86%)
Mutual labels:  annotations
dart sealed
Dart and Flutter sealed class generator and annotations, with match methods and other utilities. There is also super_enum compatible API.
Stars: ✭ 16 (-42.86%)
Mutual labels:  annotations
envelop
Envelop is a lightweight library allowing developers to easily develop, share, collaborate and extend their GraphQL execution layer. Envelop is the missing GraphQL plugin system.
Stars: ✭ 630 (+2150%)
Mutual labels:  graphql-schema
task-bundle
Scheduling of tasks for symfony made simple
Stars: ✭ 33 (+17.86%)
Mutual labels:  annotations
Easy-Fragment-Argument
This library will help you to pass and receive fragment arguments in easier way
Stars: ✭ 17 (-39.29%)
Mutual labels:  annotations
pyheartex
Heartex Python SDK - Connect your own models to Heartex Data Labeling
Stars: ✭ 27 (-3.57%)
Mutual labels:  annotations
hyperion
Experimental framework for working with IIIF in JavaScript and Typescript.
Stars: ✭ 17 (-39.29%)
Mutual labels:  annotations
aptk
A toolkit project to enable you to build annotation processors more easily
Stars: ✭ 28 (+0%)
Mutual labels:  annotations
symbok-bundle
Symfony annotations bundle
Stars: ✭ 50 (+78.57%)
Mutual labels:  annotations
twc
TypeScript based, boilerplate-less, Polymer toolbox friendly Polymer Modules
Stars: ✭ 33 (+17.86%)
Mutual labels:  annotations
PrimeAdapter
PrimeAdapter makes working with RecyclerView easier.
Stars: ✭ 54 (+92.86%)
Mutual labels:  annotations
kibana-comments-app-plugin
An application plugin to add and visualize comments to your Kibana dashboards
Stars: ✭ 36 (+28.57%)
Mutual labels:  annotations
phpunit-injector
Injects services from a PSR-11 dependency injection container to PHPUnit test cases
Stars: ✭ 62 (+121.43%)
Mutual labels:  annotations

graphql-metadata

Attach metadata to your GraphQL schema using directive like syntax.

Library supoports following formats:

  • (DEPRECATED) Annotations: Group of elements with common namespace. For example @db.length: 200
  • Marker: Single instance (key) with multiple values. For example @db length:200
  • Metadata: Directive-like config. For example @db(length: 200, columns: ['id', 'name'])

Installation

npm i graphql-metadata

Usage

Marker parsing

Markers using different syntax for elements that do not support grouping. For example @marker true etc.

Usage:

const result = parseMarker('db', `
  This is a description
  @db length:200, unique: true 
`)

No value usage:

const result = parseMarker('db', `
  This is a description
  @db
`)

Metadata parsing

Metadata uses the same syntax as GraphQL directives.

Usage:

const field: GraphQLField<any,any> = {
  ...,
  description: `@db(length:200, 
      unique: true, 
      columns: ['id', 'name']
      description: 'Some description'
    )`
}
const result = parseMetadata('db', field)

// Returns:
{
  length:200, 
  unique: true, 
  columns: ['id', 'name']
  description: 'Some description'
}

No value usage:

const field: GraphQLField<any,any> = {
  ...,
  description: '@db',
}
const result = parseMetadata('db', field)

// Returns true

Or with a string:

const result = parseMetadata('db', '@db(name: "users")')

[DEPRECATED] Annotations parsing

Here is a very basic example with a namespace (here 'db') and a description that needs to be parsed:

const { parseAnnotations } = require('graphql-metadata')

const result = parseAnnotations('db', `
  This is a description
  @db.length: 200
  @db.foo: 'bar'
  @db.unique
  @db.index: { name: 'foo', type: 'string' }
`)

console.log(result)

This will output an object containing the annotations:

{
  length: 200,
  foo: 'bar',
  unique: true,
  index: { name: 'foo', type: 'string' }
}

In a GraphQL schema, you can use the description property on GraphQLObjectType, GraphQLField...

const { parseAnnotations } = require('graphql-metadata')
const { buildSchema, isObjectType } = require('graphql')

const schema = buildSchema(`
  """
  @db.table: 'users'
  """
  type User {
    """
    @db.primary
    """
    id: ID!
  }
`)

const typeMap = schema.getTypeMap()
for (const key in typeMap) {
  const type = typeMap[key]
  // Tables
  if (isObjectType(type)) {
    const typeAnnotations = parseAnnotations('db', type.description)
    console.log(type.name, typeAnnotations)
    const fields = type.getFields()
    for (const key in fields) {
      const field = fields[key]
      const fieldAnnotations = parseAnnotations('db', field.description)
      console.log(field.name, fieldAnnotations)
    }
  }
}

Which will output:

User { table: 'users' }
id { primary: true }

Strip annotations

Sometimes it will be helpful to strip the annotations from the description. For example, you may not want to display them in a GraphQL schema explorer.

const { stripAnnotations } = require('graphql-metadata')

const result = stripAnnotations('db', `
  This is a description
  @db.length: 200
  @db.foo: 'bar'
  @db.unique
  @db.index: { name: 'foo', type: 'string' }
`)

console.log(result)

The result will be:

`
  This is a description
`
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].