# Error: Callback.apply not a function when using local resolvers with subscriptions

**URL:** <https://community.apollographql.com/t/error-callback-apply-not-a-function-when-using-local-resolvers-with-subscriptions/5762>\
**Category:** Client SDKs\
**Tags:** client, web\
**Created:** [February 18, 2023, 4:32pm UTC](https://community.apollographql.com/t/error-callback-apply-not-a-function-when-using-local-resolvers-with-subscriptions/5762 "2023-02-18T16:32:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jahson](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jahson/32/3900_2.png) [@Jahson](https://community.apollographql.com/u/Jahson)\
**Post date:** [February 18, 2023, 4:32pm UTC](https://community.apollographql.com/t/error-callback-apply-not-a-function-when-using-local-resolvers-with-subscriptions/5762/1 "2023-02-18T16:32:26Z")

</div>

Hello.  
Currently, I am working on using Apollo Client with an offline database from within an Expo Application. Using offline resolvers I was able to get it working for mutations but with subscriptions, I have been getting an error I can’t find much information on.

The error only occurs when I use the subscription hook, and is only displayed in the UI and not the console, in fact, any console logs I have placed in my resolvers don’t run so I think the resolver does not get triggered.

The error:  
`callback.apply is not a function. (In 'callback.apply(thisArg, args)', 'callback.apply' is undefined)`

My Setup:  
**App.tsx:**

```auto
// Initialize Apollo Client
const client = new ApolloClient({
  cache: new InMemoryCache(),
  // uri: "https://48p1r2roz4.sse.codesandbox.io",
  typeDefs: typeDefs,
  resolvers: resolvers,
});

...

return <ApolloProvider client={client}> .... </ApolloProvider> 

```

**TypeDefs:**

```auto
const typeDefs = `#graphql
    type User {
        username: String!
    }

    type Subscription {
        users: User!
    }
`;

```

**Resolvers:**

```auto
import { PubSub } from "graphql-subscriptions";
const pubsub = new PubSub();

const resolvers: any = {
  Query: {
    user: async (_: any, { username }: any) => {
      const user = await getUser(usernmae);
      return user;
    },
  },
  Subscription: {
    users: {
      subscribe: (_: any) => {
        console.log("Subscribe users");
        const users = observeUserList();
        //User const is a RXJS observable
        users.subscribe((user) => {
          console.log("USER HIT");
          console.log(user);
          pubsub.publish(`userList`, { user });
        });
        return pubsub.asyncIterator(`userList`);
      },
    },
  },
};

```

Usage:

```auto
import { gql, useSubscription } from "@apollo/client";

export default function Users() {
  const USERS_SUBSCRIPTION = gql`
    subscription Users {
      users @client {
        username
      }
    }
  `;

  const { loading, error, data } = useSubscription(USERS_SUBSCRIPTION);
  const [users, setUsers] = useState([] as any[]);

  useEffect(() => {
    if (data && data.users) {
      setUsers((prevUsers) => [...prevUsers, data.users]);
    }
  }, [data]);

  if (loading) {
    return <Text>Loading...</Text>;
  }

  if (error) {
    return <Text>Error: {error.message}</Text>;
  }

  return <Text>Data: {data}</Text>;
}

```

I am aware that offline resolvers are being deprecated soon, but I want to keep my local resolvers in sync with my remote ones on other graphQL servers easily as a import of the same resolvers/schema file.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![JeffAuriemma](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jeffauriemma/32/2845_2.png) [@JeffAuriemma](https://community.apollographql.com/u/JeffAuriemma)\
**Post date:** [March 14, 2023, 2:14am UTC](https://community.apollographql.com/t/error-callback-apply-not-a-function-when-using-local-resolvers-with-subscriptions/5762/2 "2023-03-14T02:14:42Z")

</div>

Hi @Jahson 👋 I haven’t used local resolvers with subscriptions so I apologize if this isn’t helpful but I’ll give it a try:

I’m looking at the following unit test in the Apollo Client code:

> <https://github.com/apollographql/apollo-client/blob/58ce462c0f4618df22214178bead9208bcb1d2ad/src/ __tests__ /local-state/subscriptions.ts#L57-L64>

The syntax used there is different from the snippet you shared. I believe the `users.subscribe` function is not being reached because there is no `subscribe` field in your `User` type. But our docs and unit tests don’t cover this functionality very well so I can’t say this with confidence. I hope that helps!

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:49pm UTC](https://community.apollographql.com/t/error-callback-apply-not-a-function-when-using-local-resolvers-with-subscriptions/5762/3 "2025-02-06T20:49:16Z")

</div>


