Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Users
    • Groups
    1. Home
    2. SDxBacon
    S
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 3
    • Best 0
    • Groups 0

    SDxBacon

    @SDxBacon

    0
    Reputation
    12
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    SDxBacon Follow

    Latest posts made by SDxBacon

    • How to use local JS files in ACP script

      Hi,

      How to require local utilities in my acpScript properly? I want to separate functions in my acpScript of my plugin into several JS files. My acpScipt is located at path public/lib/admin/index.js with codes:

      'use strict';
      
      /* globals socket, define, require */
      
      define(
        'admin/plugins/myPlugin',
        [ 'myAdminUtilities' ],
        function (util) {
          const Admin = {};
      
          Admin.init = function () {
            socket.emit(
                  'plugins.myPlugin.getData',
                  myAdminUtilities.handleResponse,
            );
          };
      
          return Admin;
        }
      );
      
      

      Then, file myAdminUtilities is located at path public/lib/admin/utils.js with codes:

      define('admin/plugins/myAdminUtilities', function () {
        const adminUtils = {};
        adminUtils.handleResponse = function (error, data) {
          // process data ...
        };
      
        return adminUtils;
      });
      

      Also, I have modified my plugin.json with following:

      {
              ...
      
              "modules": {
      		"myAdminUtilities": "public/lib/admin/utils.js"
      	},
      
              ...
      }
      

      But, I get get admin/plugins/myAdminUtilities (404 Not found) every time I enter my plugin ACP page. What's the proper way to reach my goal?

      posted in Plugin Development
      S
      SDxBacon
    • RE: NodeBB and Apollo GraphQL

      @julian thanks for your reply.

      The reason why I inject Apollo as a middleware is because of the server integrate document on Apollo website shows that we can use the apollo-server-express package to integrate GraphQL with existing Express server by adding following code:

      server.applyMiddleware({ app }); // app is from an existing express app
      

      Does router will be the express app to be passed to plugins? Because I solved this problem by passing router into .applyMiddleware() method as following changes:

      const router = params.router;
      
      apolloServer.applyMiddleware({
          app: router,
          path: '/api/mygraphql',
      });
      

      Now, the GraphQL works fine on my NodeBB server ! Hope this can help someone who run into the same problem like me. Although it looks like GraphQL is not popular in NodeBB community 🤔.

      posted in Plugin Development
      S
      SDxBacon
    • NodeBB and Apollo GraphQL

      Hi,

      I am trying to add a route into NodeBB to serve GraphQL API.
      After doing some research on Google, I find a popular package named Apollo GraphQL, which has a document to show how to integrate Apollo GraphQL server with existing Express server, can help me to do my job.

      Then, I tried to create a plugin and put the example code of graphql with a route path:/mygraphql into my library.js. But, the nodebb keep returning 404 Not found. Did I do anything wrong?

      Here is what my library.js looks like:

      const { ApolloServer, gql } = require('apollo-server-express');
      
      const books = [
      	{
      		title: 'Harry Potter and the Chamber of Secrets',
      		author: 'J.K. Rowling',
      	},
      	{
      		title: 'Jurassic Park',
      		author: 'Michael Crichton',
      	},
      ];
      
      const typeDefs = gql`
        type Book {
          title: String
          author: String
        }
      
        type Query {
          books: [Book]
        }
      `;
      
      const resolvers = {
      	Query: {
      		books: () => books,
      	},
      };
      
      const apolloServer = new ApolloServer({
      	typeDefs,
      	resolvers,
      });
      
      
      const plugin = {};
      
      plugin.init = function (params, callback) {
      	const app = params.app;
      
      	apolloServer.applyMiddleware({
      		app,
      		path: '/api/mygraphql',
      	});
      
      	callback();
      };
      
      module.exports = plugin;
      

      Thanks!

      posted in Plugin Development
      S
      SDxBacon