# ApolloServer constructor modules combination with schemaDirectives, schemaDirectives does not work

**URL:** https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813
**Category:** Server
**Tags:** server
**Created:** [July 20, 2021, 8:23am UTC](https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813 "2021-07-20T08:23:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![manish](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/manish/32/516_2.png) [@manish](https://community.apollographql.com/u/manish)
#### Post date: [July 20, 2021, 8:23am UTC](https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813/1 "2021-07-20T08:23:30Z")

</div>

here is my code:

```auto
class hasServiceDirective extends SchemaDirectiveVisitor {

  visitFieldDefinition(field) {

      const { resolve = defaultFieldResolver } = field;

      // reading directive args

      console.log(this.visitedType.name);

      const { service } = this.args;

      console.log("Inside FieldDefinition function");

      field.resolve = async (...args) => {

        const context = args[2];

        const services = context.services;

          if(services.includes(service)) {

            return await resolve.apply(this, args);

          } else {

            return "";

          }

      }

  }

}

```

```auto
const server = new ApolloServer({

   modules: [blogModule],

   schemaDirectives: {

    hasService: hasServiceDirective,

  },

  plugins: [loggingPlugin],

  context: ({event}) => {

    const headers = event.headers;

    const userId = headers.userid || null;

    const services = headers.services || null;

    return { 

      userId,

      services,

      prisma

     };

  },

   playground: {

    //endpoint: "/dev/graphql"

    settings: {

      'schema.polling.enable': false,

      'schema.polling.interval': 5000,

    }

   }

});

```

```auto
const books = [

  {

    title: 'The Awakening',

    author: 'Kate Chopin',

  },

  {

    title: 'City of Glass',

    author: 'Paul Auster',

  },

];

const users = [

  {

    name: 'Manish',

    password: 'manish@123',

  },

  {

    name: 'Monu',

    password: 'monu@123',

  },

];

```

If i user typeDefs, resolver property in apolloServer, my custom Directive is working but when i use modules, it isn’t working. I will have many typeDefs and resolvers in future so I m using modules property of ApolloServer constructor to call schemas.

---

<div class="post-metadata">

### Author: ![abernix](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/abernix/32/10_2.png) [@abernix](https://community.apollographql.com/u/abernix)
#### Post date: [July 20, 2021, 9:19am UTC](https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813/2 "2021-07-20T09:19:56Z")

</div>

What version of Apollo Server are you using?

---

<div class="post-metadata">

### Author: ![manish](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/manish/32/516_2.png) [@manish](https://community.apollographql.com/u/manish)
#### Post date: [August 2, 2021, 2:06pm UTC](https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813/3 "2021-08-02T14:06:52Z")

</div>

Hi @abernix sorry for late reply.  
I was using apollo server v3.0…I found that apollo server 3.0 does not have documentation for customDirective. Now I m on 2.xx.x version. Now it is working.

I assume apollo server v3.0 does not support Custom Directives?

---

<div class="post-metadata">

### Author: ![abernix](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/abernix/32/10_2.png) [@abernix](https://community.apollographql.com/u/abernix)
#### Post date: [August 10, 2021, 5:52pm UTC](https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813/4 "2021-08-10T17:52:26Z")

</div>

This is covered in [the migration guide for v3](https://www.apollographql.com/docs/apollo-server/migration/#schemadirectives).

---

<div class="post-metadata">

### Author: ![StephenBarlow](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/stephenbarlow/32/25_2.png) [@StephenBarlow](https://community.apollographql.com/u/StephenBarlow)
#### Post date: [August 11, 2021, 12:01am UTC](https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813/5 "2021-08-11T00:01:56Z")

</div>

Ah yes, and we’ve restored the [custom directives article](https://www.apollographql.com/docs/apollo-server/schema/creating-directives/) in the 3.x documentation with updated instructions.

---

<div class="post-metadata">

### Author: ![manish](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/manish/32/516_2.png) [@manish](https://community.apollographql.com/u/manish)
#### Post date: [August 11, 2021, 6:12am UTC](https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813/6 "2021-08-11T06:12:52Z")

</div>

Thanks @abernix and @StephenBarlow for the update.

---

<div class="post-metadata">

### Author: ![abernix](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/abernix/32/10_2.png) [@abernix](https://community.apollographql.com/u/abernix)
#### Post date: [August 11, 2021, 6:52am UTC](https://community.apollographql.com/t/apolloserver-constructor-modules-combination-with-schemadirectives-schemadirectives-does-not-work/813/7 "2021-08-11T06:52:56Z")

</div>


