xenial-black
xenial-black3w ago

Does refine provide a mock data endpoint?

Im using graphql and need mock data in order to develop my front export const API_BASE_URL = 'https://api.crm.refine.dev' export const API_URL = ${API_BASE_URL}/graphql export const WS_URL = 'wss://api.crm.refine.dev/graphql' are this the right endpoints? Which is the demo user ? "michael.scott@dundermifflin.com" not found
12 Replies
kapa.ai
kapa.ai3w ago
Hi @nachozobian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, refine does provide mock data endpoints, including for GraphQL. However, the specific endpoints you mentioned are for a CRM template example and may not be suitable for general development purposes. Let me explain further: 1. Mock Data for GraphQL: Refine offers a GraphQL data provider that can work with mock data. As mentioned in the GraphQL Data Provider documentation, you can use a mock API URL like this:
export const API_URL = "<https://api.nestjs-query.refine.dev/graphql";>
export const API_URL = "<https://api.nestjs-query.refine.dev/graphql";>
2. CRM Template Endpoints: The endpoints you provided (https://api.crm.refine.dev/graphql and wss://api.crm.refine.dev/graphql) are specific to the CRM dashboard template example. These are not general-purpose mock data endpoints, but rather part of a specific demo. 3. Demo User: The knowledge sources don't provide specific information about a demo user for the CRM template. However, for other refine examples, demo credentials are often provided. For instance, the Strapi v4 example uses: Username: demo@refine.dev Password: demodemo For your development purposes, I would recommend using the general GraphQL mock endpoint (https://api.nestjs-query.refine.dev/graphql) rather than the CRM-specific one, unless you're specifically working with the CRM template. If you need more detailed information about setting up mock data for your GraphQL-based refine project, you might want to check the GraphQL Data Provider documentation for the most up-to-date and relevant information. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@689499357074030645> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-black
xenial-blackOP3w ago
@kapa.ai im using the crm endpoint "michael.scott@dundermifflin.com" not found why is this? This is my auth.ts code login: async ({ email }) => { try { const { data } = await dataProvider.custom({ url: API_URL, method: "post", headers: {}, meta: { variables: { email }, rawQuery: mutation Login($email: String!) { login(loginInput: { email: $email }) { accessToken, } } , }, }); localStorage.setItem("access_token", data.login.accessToken); return { success: true, redirectTo: "/", }; } catch (e) { const error = e as Error; return { success: false, error: { message: "message" in error ? error.message : "Login failed", name: "name" in error ? error.name : "Invalid email or password", }, }; }
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the information provided in the knowledge sources, it appears that you're encountering an issue with the CRM demo endpoint. Let me address your question: The error "michael.scott@dundermifflin.com not found" suggests that the email you're using is not recognized by the system. This could be due to a couple of reasons: 1. Temporary Issue: According to the GitHub issue #5959, there was a known issue with the CRM backend where it was redeploying every 4 hours to reset its data. This could cause temporary authentication problems. However, this issue was reportedly resolved. 2. Incorrect Demo Credentials: The email "michael.scott@dundermifflin.com" is not mentioned as a valid demo user in the provided knowledge sources. It's possible that this email is not part of the demo data set. To resolve this, you could try the following: 1. Use the correct demo email: While the exact demo credentials for the CRM example are not provided in the knowledge sources, you could try using "demo@refine.dev" as the email, which is mentioned as a demo email in other refine examples. 2. Check for recent updates: The CRM demo might have been updated recently. You may want to check the latest documentation or the refine GitHub repository for the most up-to-date demo credentials. 3. Ensure you're using the correct endpoint: Confirm that you're using the correct API_URL for the CRM demo. If the issue persists, it might be worth reaching out to the refine team through their GitHub issues, as they've been responsive to similar authentication issues in the past, as evidenced by the GitHub issue #6283. Regarding your auth.ts code, it looks structurally correct for a GraphQL-based login. However, make sure that the API_URL you're using matches the CRM demo endpoint you mentioned earlier. If you continue to face issues, consider using a more general-purpose mock GraphQL endpoint for development, as suggested in my previous response, until you can resolve the CRM demo authentication problem. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@689499357074030645> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-black
xenial-blackOP3w ago
@kapa.ai index.ts code import graphqlDataProvider, { GraphQLClient, liveProvider as graphqlLiveProvider } from "@refinedev/nestjs-query"; import { createClient } from 'graphql-ws' import { fetchWrapper } from "./fetch-wrapper";
export const API_BASE_URL = 'https://api.crm.refine.dev/graphql' export const API_URL = ${API_BASE_URL}/graphql export const WS_URL = 'wss://api.crm.refine.dev/graphql'
export const client = new GraphQLClient(API_URL, { fetch: (url: string, options: RequestInit) => { try { return fetchWrapper(url, options); } catch (error) { return Promise.reject(error as Error); } } })
export const wsClient = typeof window !== "undefined" ? createClient({ url: WS_URL, connectionParams: () => { const accessToken = localStorage.getItem("access_token");
return { headers: { Authorization: Bearer ${accessToken}, } } } }) : undefined
export const dataProvider = graphqlDataProvider(client); export const liveProvider = wsClient ? graphqlLiveProvider(wsClient) : undefined; It worked yesterday
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- I'm glad to hear that it worked yesterday. Based on the code you've shared and the information from the knowledge sources, it appears you're using the correct setup for the refine CRM demo. However, if you're experiencing issues today, there might be a few reasons for this: 1. Temporary Backend Issues: As mentioned in the GitHub issue #5959, the CRM backend is designed to reset its data periodically. A refine team member stated: "CRM backend was re-deploying every 4 hours to reset delete it's data and seed again. This happens during the deployment. Now we've changed it and DB will refresh it's data without deployments, so we should have now downtime." While this change should have reduced downtime, it's possible that you might still encounter brief periods where the backend is refreshing its data. 2. Authentication Token: Your code correctly retrieves the access token from localStorage. Make sure that your login process is successfully storing the token, and that it hasn't expired. 3. API Endpoint Changes: Although unlikely, it's possible that the API endpoints might have changed. You can verify if these are still the correct endpoints:
export const API_BASE_URL = '<https://api.crm.refine.dev/graphql'>
export const API_URL = `${API_BASE_URL}/graphql`
export const WS_URL = 'wss://api.crm.refine.dev/graphql'

export const API_BASE_URL = '<https://api.crm.refine.dev/graphql'>
export const API_URL = `${API_BASE_URL}/graphql`
export const WS_URL = 'wss://api.crm.refine.dev/graphql'

4. Network Issues: Ensure that your network connection is stable and that you can reach the API endpoints. If the issue persists, you might want to: 1. Check the browser console for any error messages that could provide more insight into the problem. 2. Verify that your login process is working correctly and storing the access token in localStorage. 3. Try clearing your browser cache and local storage, then logging in again. If none of these steps resolve the issue, it might be worth reaching out to the refine team through their GitHub issues or Discord support for the most up-to-date information on the CRM demo endpoints and any known issues. Remember, demo environments can sometimes be unstable or change without notice. If you're developing a production application, you might want to consider setting up your own backend or using a more stable mock data source for consistent development. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@689499357074030645> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-black
xenial-blackOP3w ago
@kapa.ai provide me a query to test the endpoint
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Certainly! I can provide you with a query to test the CRM demo endpoint. Based on the information from the knowledge sources, here's a simple query you can use to test the GraphQL endpoint:
query {
companies(paging: { first: 5 }) {
nodes {
id
name
totalRevenue
}
}
}
query {
companies(paging: { first: 5 }) {
nodes {
id
name
totalRevenue
}
}
}
This query fetches the first 5 companies from the CRM demo, including their id, name, and totalRevenue. You can use this query with the GraphQL client you've set up in your index.ts file. Here's how you might use this query in your code:
import { client } from './index';

const testQuery = async () => {
try {
const { data } = await client.request(`
query {
companies(paging: { first: 5 }) {
nodes {
id
name
totalRevenue
}
}
}
`);
console.log('Query result:', data);
} catch (error) {
console.error('Error executing query:', error);
}
};

testQuery();
import { client } from './index';

const testQuery = async () => {
try {
const { data } = await client.request(`
query {
companies(paging: { first: 5 }) {
nodes {
id
name
totalRevenue
}
}
}
`);
console.log('Query result:', data);
} catch (error) {
console.error('Error executing query:', error);
}
};

testQuery();
This code snippet uses the GraphQL client you've defined to send the query to the API endpoint. It will log the result to the console if successful, or log any errors if they occur. Remember to ensure that you're authenticated before running this query, as the CRM demo likely requires authentication for data access. If you encounter any issues with this query, it might indicate problems with your connection to the API, authentication, or potential changes in the API schema. In such cases, you may want to check your network connection, verify your authentication token, or consult the latest refine documentation for any updates to the CRM demo. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@689499357074030645> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
magic-amber
magic-amber2w ago
Hello @nachozobian Yeah these are correct. https://github.com/refinedev/refine/blob/main/examples/app-crm-minimal/src/providers/auth.ts#L10 https://github.com/refinedev/refine/blob/main/examples/app-crm-minimal/src/providers/data/index.ts I'm not sure you why you are getting "not found" error. Our example is working without problem Maybe you can check our implementation to check for errors

Did you find this page helpful?