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 custom directives #66

Closed
kabytaa opened this issue Jan 19, 2018 · 6 comments
Closed

Support custom directives #66

kabytaa opened this issue Jan 19, 2018 · 6 comments

Comments

@kabytaa
Copy link

kabytaa commented Jan 19, 2018

Hi,

I am not sure if there is a support for custom directives or i'm doing something wrong.
I have this code:

directive @myDirective on FIELD

type Query{
    getData:String! @myDirective
}

And i get this error:

[graphql] Directive "noLogin" may not be used on FIELD_DEFINITION. (KnownDirectives)

How i can fix it?

BTW: Awesome extension.

Thanks

@Mayank1791989
Copy link
Collaborator

Please share your .gqlconfig file.

@kabytaa
Copy link
Author

kabytaa commented Jan 19, 2018

my .gqlconfig file

// .gqlconfig (with query) 
{
  schema: {
    files: 'src/**/*.gql',
  },
  query: {
    files: [
      // query gql files 
      {
        match: 'src/**/*.gql',
        parser: 'QueryParser',
      },
      // [Embedded queries] relay files 
      {
        match: { include: 'src/**/*.js', ignore: '**/tests/**/*.js' },
        parser: [ 'EmbeddedQueryParser', { startTag: 'Relay\\.QL`', endTag: '`' } ],
        isRelay: true,
      },
      // [Embedded queries] gql tag files 
      {
        match: { include: 'src/**/*.js', ignore: '**/tests/**/*.js' },
        parser: [ 'EmbeddedQueryParser', { startTag: 'gql`', endTag: '`' } ],
      },
      // [Embedded queries] some other tags  
      {
        match: 'src/**/*.xyz',
        parser: [ 'EmbeddedQueryParser', { startTag: '"""', endTag: '"""' } ],
      },
      // [Embedded queries] some other tags and modify validation rules 
      {
        match: 'src/**/*.xyz',
        parser: [ 'EmbeddedQueryParser', { startTag: '"""', endTag: '"""' } ],
        validate: {
          extends: 'gql-rules-query',
          rules: {
            LoneAnonymousOperation: 'off',
            NoUnusedVariables: 'warn',
          },
        }
      },
    ]
  }
}

I tried to change the file for following json and it stoped to show me the error.

// .gqlconfig (with query) 
{
  schema: {
    files: 'src/**/*.gql',
  }
}

what is the problem with the previous file?

Thanks

@kumarharsh
Copy link
Owner

kumarharsh commented Jan 19, 2018

The previous file is an example file - meant to show how to configure your project.

The errors have stopped because the linting has stopped. You need to specify the query config depending on the files you want linting, autocomplete, etc to be activated for.

For example, to enable linting, etc for *.gql and *.js files, write this:

// .gqlconfig (with query) 
{
  schema: {
    files: 'src/**/*.gql',
  },
  query: {
    files: [
      // query gql files 
      {
        match: 'src/**/*.gql',
        parser: 'QueryParser',
      },
      // [Embedded queries] relay files 
      {
        match: { include: 'src/**/*.js', ignore: '**/tests/**/*.js' },
        parser: [ 'EmbeddedQueryParser', { startTag: 'Relay\\.QL`', endTag: '`' } ],
        isRelay: true,
      },
    ]
  }
}

@Mayank1791989
Copy link
Collaborator

what is the problem with the previous file?

{
  schema: {
    files: 'src/**/*.gql',
  }
}

The above .gqlconfig file is fine if you are using plugin for schema files only but if you want to support queries (using apollo, relay or other any other client) than you need to add 'query' in .gqlconfig.

I tried to change the file for following json and it stoped to show me the error.

It stopped showing error as currently in schema directive validation is not done (I have created an issue
see here Mayank1791989/gql#93).

But with other config its showing error because you put schema files in query also and the error is coming from query validation rules. Note In graphql schema and query files are different and you should not put schema files in query files config they should be separate.

{
   schema: {
      files: 'src/**/*.gql',
  },
  query: {
    files: [{
-    match: 'src/**/*.gql'
+    match: 'src/path_to_query_files_not_schema_files',
    }]
  }
}

[graphql] Directive "noLogin" may not be used on FIELD_DEFINITION. (KnownDirectives)

directive @myDirective on FIELD

type Query{
    getData:String! @myDirective
}

In above code the @myDirective type definition is wrong. If you want to use directive on type definition fields than you should define your directive as below.

- directive @myDirective on FIELD
+ directive @myDirective on FIELD_DEFINITION

@kumarharsh
Copy link
Owner

I believe this has been resolved @kabytaa?

@kabytaa
Copy link
Author

kabytaa commented Jun 30, 2018

Yes, it solved, Thanks to @Mayank1791989.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants