Neo4j/Cypher 将节点标签列表的第一个元素作为属性返回

问题描述

我正在尝试将单个节点标签作为密码查询中的属性返回。我正在使用 GRANDstack,所以我希望 GraphQL 向 Neo4j 询问节点列表,每个节点都带有标签作为属性

import React,{ useRef } from 'react';
// import { data } from './data/data';
import { useState,useEffect } from 'react';
import Form from 'react-bootstrap/Form';
import ScrollToTop from './ScollToTop';

const DropDown = (props) => {
    console.log(props.storesData.id)

    const [storeCategorys,setStoreCategories] = useState(props.storesCategorysData);
    const [initialValues,setinitialValues] = useState(props.storesData);

    const handleOnchange = (event) => {
        const filter = event.target.id;
        const initialState = [...initialValues]
        setValues(initialState.filter(store => 
            {return (store.store-category.indexOf(filter) >= 0)}
        ));
    }

    const defaultSelectMessage = 'select a category';

    return (
        <Form>
            <Form.Group controlId="exampleForm.SelectCustom">
            <Form.Label>Custom select</Form.Label>
            <Form.Control defaultValue={defaultSelectMessage} onChange={(e) => handleOnchange(e)} as="select" custom>
                <option hidden disabled value={defaultSelectMessage}>{defaultSelectMessage}</option>
                {storeCategorys.map((item,index) => (
                <option id={item.id} key={index}>{item}</option>
                ))}
            </Form.Control>
            </Form.Group>
        </Form>
    );
}

const Filter = (props) => {
    return (
        <div>
            {props.alphabet.split("").map((c,i) => {
                return (
                    <>
                    {props.filteredValues
                    .filter(store => store.title.rendered.startsWith(c)).length === 0 
                    ? <h1 ref={ el => props.itemsRef.current[i] = el } className={'Grey'}>{c}</h1>
                    : <h1 ref={ el => props.itemsRef.current[i] = el } className={'notGrey'}>{c}</h1>   
                    }
                    
                    {props.filteredValues
                    .filter(store => store.title.rendered.startsWith(c))
                    .map((item,index) => (   
                        <li key={index}>{item.title.rendered}</li>
                    ))}
                    
                    </>
                );
            })}
        </div>
    );
}

const AlphaButtons = (props) => {

    const alphabet = "abcdefghijklmnopqrstuvwxyz";
    const alphabetIntoArray = alphabet.split("");

    const itemsRef = useRef([]);

    useEffect(() => {
        itemsRef.current = itemsRef.current.slice(0,alphabetIntoArray.length);
    },[alphabetIntoArray])

    const goToSelection = (event,index) => {
        if(itemsRef.current[index]) {
            itemsRef.current[index].scrollIntoView({
            behavIoUr: "smooth",block: "nearest"
            })
        }
    }

    return (
    <>
        {alphabet.split("").map((item,index) => (
            <button key={index} onClick={(e) => goToSelection(e,index)}>{item}</button>
        ))}  

        <Filter filteredValues={filteredValues} alphabet={alphabet} itemsRef={itemsRef}/>    
    </>
    )
}

const StoreDirectory = (props) => {
    const [filteredValues,setValues] = useState(props.storesData);

    console.log(props)
    

    return (
        <>
            <DropDown props={props}/>
            <AlphaButtons filteredValues={filteredValues}/> 
            <ScrollToTop />
        </>
    )

}

export default StoreDirectory;

我正在尝试为此使用 query GetPushNotificationsByUser($userId: ID!) { GetPushNotificationsByUser(userId: $userId) { id,label,title,message,status,externalUrl,createdAt { formatted } } } head() 函数,但到目前为止未成功:

labels()

MATCH (u:User {id: $userId})<-[:NOTIFIES]-(pn:PushNotification {status: 'SENT'})
WITH head(labels(pn)) as label,pn
RETURN pn
ORDER BY pn.createdAt DESC

两者都返回“PushNotifications”,但没有标签属性。有谁知道我如何实现这一目标?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)