SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.21k stars 662 forks source link

How to Integrate GraphQL Api With AdminBRo #481

Closed harsh-solutelabs closed 3 years ago

harsh-solutelabs commented 4 years ago

Is there any way to integrate graphql API with the admin panel?

wojtek-krysiak commented 4 years ago

you would need to create a custom adapter which implements BaseResource. Take a look at how admin-bro-mongoose is done: https://github.com/SoftwareBrothers/admin-bro-sequelizejs/blob/master/src/resource.js

then you can pass this resource to options like this:

const MyResource = require('path-to-my-resource')

const AdminBroOptions = {
  resources: [new MyResource(...params_passed_to_your_constructor)]
}
harsh-solutelabs commented 4 years ago

How I can use that graphql API in a custom component because to call that mutation I want to wrap the custom component with Appollo server?

wojtek-krysiak commented 4 years ago

Unfortunately, I don't have any experience with apollo and react so I cannot help you :(

HeetGosaliya commented 4 years ago

client.jsx

import ApolloClient, { InMemoryCache } from 'apollo-boost';
export default new ApolloClient({
  headers: {
    Authorization:'Bearer sometoken'
  },
  uri: 'graphql end point',
  cache: new InMemoryCache(),
});

dashboard.jsx

import React from 'react';
import Demo from './demo';
import { ApolloProvider } from 'react-apollo';
import client from './client';

const Dashboard = props => {
  return (
    <ApolloProvider client={client}>
     <Demo />
    </ApolloProvider>
  );
};
export default Dashboard;

demo.jsx

import React from "react";
import {useQuery} from "react-apollo";

const Demo = props => {
const {data,loading,error} = useQuery(SOME_QUERY);
if(data){
console.log(data);
}
return (
     <p>Hello world</p>
);
};
export default Demo;

@wojtek-krysiak we can use this approach to connect with GraphQl :)

wojtek-krysiak commented 3 years ago

we have hasura integration in the backlog #655 (WIP)